回答編集履歴
1
回答を追記
answer
CHANGED
@@ -75,4 +75,69 @@
|
|
75
75
|
Log.e("My App", str);
|
76
76
|
text.add(str);
|
77
77
|
}
|
78
|
+
```
|
79
|
+
|
80
|
+
# 追記
|
81
|
+
sample.txt
|
82
|
+
```
|
83
|
+
1 2 3
|
84
|
+
4 5 6 0
|
85
|
+
7 8 9
|
86
|
+
10 11 12
|
87
|
+
```
|
88
|
+
Main.java
|
89
|
+
```java
|
90
|
+
import java.io.BufferedReader;
|
91
|
+
import java.io.FileInputStream;
|
92
|
+
import java.io.IOException;
|
93
|
+
import java.io.InputStream;
|
94
|
+
import java.io.InputStreamReader;
|
95
|
+
import java.util.ArrayList;
|
96
|
+
import java.util.List;
|
97
|
+
|
98
|
+
public class Main {
|
99
|
+
|
100
|
+
public static void main(String[] args) throws IOException {
|
101
|
+
int[][] nums;
|
102
|
+
|
103
|
+
InputStream is;
|
104
|
+
BufferedReader br;
|
105
|
+
|
106
|
+
// //////////////////////////////////////////////////////
|
107
|
+
is = new FileInputStream("sample.txt");
|
108
|
+
br = new BufferedReader(new InputStreamReader(is));
|
109
|
+
|
110
|
+
List<int[]> table = new ArrayList<int[]>();
|
111
|
+
|
112
|
+
String str;
|
113
|
+
while ((str = br.readLine()) != null) {
|
114
|
+
String[] splitted = str.trim().split(" ");
|
115
|
+
if (splitted.length < 3) {
|
116
|
+
throw new IllegalStateException("Too few element.");
|
117
|
+
}
|
118
|
+
|
119
|
+
int[] row = new int[3];
|
120
|
+
for (int i = 0; i < 3; i++) {
|
121
|
+
row[i] = Integer.parseInt(splitted[i]);
|
122
|
+
}
|
123
|
+
table.add(row);
|
124
|
+
}
|
125
|
+
nums = table.toArray(new int[][] {});
|
126
|
+
// //////////////////////////////////////////////////////
|
127
|
+
|
128
|
+
for (int[] num : nums) {
|
129
|
+
for (int n : num) {
|
130
|
+
System.out.print(n + ",");
|
131
|
+
}
|
132
|
+
System.out.println();
|
133
|
+
}
|
134
|
+
}
|
135
|
+
}
|
136
|
+
```
|
137
|
+
実行結果
|
138
|
+
```
|
139
|
+
1,2,3,
|
140
|
+
4,5,6,
|
141
|
+
7,8,9,
|
142
|
+
10,11,12,
|
78
143
|
```
|