我有一个包含信息的文件。看起来像:
Michael 19 180 Miami
George 25 176 Washington
William 43 188 Seattle
我想拆分行和字符串并阅读它们。我希望它看起来像:
Michael
19
180
Miami
George
...
我使用了这样的代码:
BufferedReader in = null;
String read;
int linenum;
try{
in = new BufferedReader(new FileReader("fileeditor.txt"));
}
catch (FileNotFoundException e) {System.out.println("There was a problem: " + e);}
try{
for (linenum = 0; linenum<100; linenum++){
read = in.readLine();
if(read == null){}
else{
String[] splited = read.split("\\s+");
System.out.println(splited[linenum]);
}
}
}
catch (IOException e) {System.out.println("There was a problem: " + e);}
}
这给了我什么
Michael
25
188
我认为这可能是我的 for 循环的问题,但我在编程方面不是很先进,我将不胜感激。谢谢。