Reading Text from a File

try { BufferedReader in = new BufferedReader(new FileReader("infilename")); String str; while ((str = in.readLine()) != null) { process(str); } in.close(); } catch (IOException e) { }

Comments

14 Jan 2010 - 11:55pm by Anonymous (not verified)

good example.

14 Jan 2010 - 11:57pm by jojo (not verified)

It is really nice that I knew buffered reader.

29 Jan 2010 - 2:41am by Balu (not verified)

Simple and good example.

3 Feb 2010 - 11:22pm by Abbee (not verified)

I need more help with this.

4 Feb 2010 - 1:51pm by Anonymous (not verified)

thanks exactly what i needed

23 Feb 2010 - 11:27am by Gervase (not verified)

Thanks for this. Been coding for many years, but always come back here to refresh my memory. And I did buy your book too. Just that this is easier to search.

3 Mar 2010 - 9:55am by Anonymous (not verified)

Process doesnt work for my program!

5 Mar 2010 - 1:29pm by Jone (not verified)

Thanx...

6 Mar 2010 - 6:08am by Ollie (not verified)

Do you have to import anything for this to work?

18 Mar 2010 - 5:16am by Anonymous (not verified)

I'm not familiar with this site but I think anything with italic blue text (infilename and process(str)" is meant to be pseudocode, aka replaced with the actual code for your specific needs.

The "process(str)" is basically pseudocode for whatever you want to do with the incoming text; literally it means "here is where you process the string.

Replace "process(str);" with something like "vector.add(str);" or "array[x] = str;", basically customize it to your needs.

Hope this helps.

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.