Reputation: 349
I don't know how to explain this, but I have data like
1 John US 38 24 090921
2 Dave UK 29 12 043721
3 James US 31 87 823874
The data separated by tab
and I just want to read my data like this
1 John US 38
2 Dave UK 29
3 James US 31
How can I do like that in Java? can you show me the sample of codes too? Thank You.
Upvotes: 2
Views: 99
Reputation: 473
I think this will help you in your case.
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader("filename"));
String read = null;
while ((read = in.readLine()) != null) {
String[] splited = read.split("\\s+");
for (String part : splited) {
System.out.println(part); // to read the data is inputted correctly or not
}
}
} catch (IOException e) {
System.out.println("There was a problem: " + e);
e.printStackTrace();
} finally {
try {
in.close();
} catch (Exception e) {
}
}
Upvotes: 1