包含整数的输入文件将如下所示:
5 2 3 5
2 4 23 4 5 6 4
那么我将如何阅读第一行,用空格分隔并将这些数字添加到 Arraylist1。然后读取第二行,用空格分隔并将数字添加到 ArrayList2 等等。(所以 Arraylist1 将包含 [5,2,3,5] 等)
FileInputStream fstream = new FileInputStream("file.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String data;
while ((data = br.readLine()) != null) {
//How can I do what I described above here?
}