I have a file with information in it. It looks like:
Michael 19 180 Miami
George 25 176 Washington
William 43 188 Seattle
I want to split the lines and strings and read them. I want it to look like:
Michael
19
180
Miami
George
...
i used a code like this:
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);}
}
What this gave me was
Michael
25
188
I think its probably an issue with my for loop but I'm not very advanced in programming and I'll appreciate help. Thanks.
See Question&Answers more detail:os