回答編集履歴
2
追記
test
CHANGED
@@ -105,3 +105,59 @@
|
|
105
105
|
}
|
106
106
|
|
107
107
|
```
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
---
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
(追記)
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
Java8だと、こういうやり方もあります。
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
```lang-java
|
124
|
+
|
125
|
+
import java.io.*;
|
126
|
+
|
127
|
+
import java.nio.file.*;
|
128
|
+
|
129
|
+
import java.util.*;
|
130
|
+
|
131
|
+
import java.util.stream.*;
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
public final class App {
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
public static void main(String[] args) {
|
140
|
+
|
141
|
+
try (Stream<String> lines = Files.lines(Paths.get("input.txt"))) {
|
142
|
+
|
143
|
+
lines.forEach(x -> {
|
144
|
+
|
145
|
+
int[] intArray = Stream.of(x.split(" ")).mapToInt(Integer::parseInt).toArray();
|
146
|
+
|
147
|
+
System.out.println("int array=" + Arrays.toString(intArray));
|
148
|
+
|
149
|
+
});
|
150
|
+
|
151
|
+
} catch (IOException e) {
|
152
|
+
|
153
|
+
e.printStackTrace();
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
```
|
162
|
+
|
163
|
+
|
1
throws FileNotFoundExceptionについて追記
test
CHANGED
@@ -33,6 +33,8 @@
|
|
33
33
|
// import java.util.*; // Iterator, Scanner
|
34
34
|
|
35
35
|
|
36
|
+
|
37
|
+
// コンストラクター Scanner(File) は throws FileNotFoundException
|
36
38
|
|
37
39
|
try (Scanner scanner = new Scanner(new File("ファイル名"))) {
|
38
40
|
|