51,411
社区成员
发帖
与我相关
我的任务
分享public static void main(String arg[]) throws IOException {
File file = new File("D:", "test.txt");
String line;
List<Integer> list = new ArrayList<>();
String temp[];
BufferedReader in = new BufferedReader(new FileReader(file));
while ((line = in.readLine()) != null) {
temp = line.split("\n");
for (int j = 0; j < temp.length; j++) {
list.add(Integer.parseInt(temp[j]));
System.out.println("shuzu is "+temp[j]);
}
}
in.close();
System.out.println(list);
// for(int i=0;i<100000;i++){
// System.out.println(list);
// }
}[/quote]
就是我想把txt文件中的数据读出来写入一个数组中,但是窝在测试数组打印出来全部都是0啊,不知道为什么public static void main(String arg[]) throws IOException {
File file = new File("D:", "test.txt");
String line;
List<Integer> list = new ArrayList<>();
String temp[];
BufferedReader in = new BufferedReader(new FileReader(file));
while ((line = in.readLine()) != null) {
temp = line.split("\n");
for (int j = 0; j < temp.length; j++) {
list.add(Integer.parseInt(temp[j]));
System.out.println("shuzu is "+temp[j]);
}
}
in.close();
System.out.println(list);
// for(int i=0;i<100000;i++){
// System.out.println(list);
// }
}