質問編集履歴

1

情報の追加

2017/05/14 08:11

投稿

monyu_
monyu_

スコア7

test CHANGED
File without changes
test CHANGED
@@ -81,3 +81,165 @@
81
81
  いろいろ試してみたのですが”,”が来た時の処理の仕方がよくわかりません
82
82
 
83
83
  説明が分かりにくかったかもしれませんがどうかご教授お願いします
84
+
85
+
86
+
87
+ **追記**
88
+
89
+
90
+
91
+ 一応すべてのコードとエラーを書きます
92
+
93
+ ```java
94
+
95
+ import java.io.BufferedReader;
96
+
97
+ import java.io.File;
98
+
99
+ import java.io.FileReader;
100
+
101
+ import java.io.IOException;
102
+
103
+ import java.io.PrintWriter;
104
+
105
+ import java.util.ArrayList;
106
+
107
+
108
+
109
+ public class GameMain {
110
+
111
+
112
+
113
+ public static void main(String[] args) {
114
+
115
+ // TODO 自動生成されたメソッド・スタブ
116
+
117
+ int[] data=new int[40];
118
+
119
+
120
+
121
+ try{
122
+
123
+ BufferedReader br = new BufferedReader(new FileReader("f:\\Test\\MKDir\\test.txt"));
124
+
125
+ String s;
126
+
127
+ s=br.readLine();
128
+
129
+ System.out.println(s);
130
+
131
+ br.close();
132
+
133
+
134
+
135
+ //文字から数字に変換-------------------------------
136
+
137
+ String[] numStrings = s.split(",");
138
+
139
+ ArrayList numbers = new ArrayList();
140
+
141
+
142
+
143
+ for(String str : numStrings){
144
+
145
+ str = str.trim();
146
+
147
+ int num = Integer.parseInt(str);//33行目
148
+
149
+ numbers.add(num);
150
+
151
+ System.out.print(numbers);
152
+
153
+ }
154
+
155
+ //System.out.print(data[0]);
156
+
157
+ }catch(IOException e){
158
+
159
+ System.out.println("ファイル読み込みエラー");
160
+
161
+ }
162
+
163
+ }
164
+
165
+
166
+
167
+ /*
168
+
169
+ * フォルダーの製作
170
+
171
+ */
172
+
173
+ public static void MKFolder(){
174
+
175
+ File f = new File("f:\\Test\\MKDir");
176
+
177
+ boolean r = f.mkdirs();
178
+
179
+ System.out.println("結果= "+r);
180
+
181
+ }
182
+
183
+
184
+
185
+ /*
186
+
187
+ * テキストに文字列を書き込み
188
+
189
+ */
190
+
191
+ public static void MKText(){
192
+
193
+ try{
194
+
195
+ PrintWriter pw = new PrintWriter("f:\\Test\\MKDir\\test.txt");
196
+
197
+ pw.println("プログラムテスト");
198
+
199
+ pw.println("プログラムテスト2");
200
+
201
+ pw.close();
202
+
203
+ System.out.println("書き込み成功");
204
+
205
+ }catch(IOException e){
206
+
207
+ System.out.println("ファイル書き出しエラー");
208
+
209
+ }
210
+
211
+ }
212
+
213
+
214
+
215
+ }
216
+
217
+ ```
218
+
219
+
220
+
221
+ ```text
222
+
223
+ 1234,5678,1,23,156,78912,345,6789,123
224
+
225
+ ```
226
+
227
+
228
+
229
+ ```ここに言語を入力
230
+
231
+ 1234,5678,1,23,156,78912,345,6789,123
232
+
233
+ Exception in thread "main" java.lang.NumberFormatException: For input string: "1234"
234
+
235
+ at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
236
+
237
+ at java.lang.Integer.parseInt(Integer.java:580)
238
+
239
+ at java.lang.Integer.parseInt(Integer.java:615)
240
+
241
+ at tnw.game.g29.GameMain.main(GameMain.java:33)
242
+
243
+
244
+
245
+ ```