Rahul Kalidindi
Rahul Kalidindi

Reputation: 4736

How to parse a text file in java?

I have a text file in the following url.

http://hosted.stats.com/ifb2009/data.asp?file=en/chlg_standings.txt

I want to parse this text file and display the data as groups, teams etc. Can anyone please let me know how to parse text file.

Upvotes: 0

Views: 1108

Answers (3)

Snicolas
Snicolas

Reputation: 38168

It's a java question, not an android specific question.

The best is to use a BufferedReader on your file (or stream). Then use readLine to get one line.

Then use String.split or String.indexOf to parse your data.

Upvotes: 2

Voo
Voo

Reputation: 30235

Probably the best thing to do is use a Scanner that way you can easily specify your used delimiters and read data in its correct form (readXXX()). Also you can use the same logic independent of where the file is from by replacing the Stream in the constructor with another.

Upvotes: 2

Haphazard
Haphazard

Reputation: 10948

String.split(..) if it is simple. If it is more complex, you could use regex

Upvotes: 1

Related Questions