Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #26030
| From | Jim Janney <jjanney@shell.xmission.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Shortest way to read all lines (one by one) from a text file? |
| Date | 2011-02-11 08:23 -0700 |
| Organization | As little as possible |
| Message-ID | <2pk4h6oasc.fsf@shell.xmission.com> (permalink) |
| References | <4d54f158$0$6975$9b4e6d93@newsspool4.arcor-online.net> |
rob@wenger.net (Robin Wenger) writes:
> Ok, I know in general a way to read text lines ony-by-one from a file into a string variable.
> But I miss somehow a short one-liner like:
>
>
> foreach(String currentline : file("D:\test\myfile.txt")) {
> ....
> }
>
> Is there something like this in Java?
> What would be the shortest way otherwise?
>
http://commons.apache.org/io/api-1.4/org/apache/commons/io/FileUtils.html#readLines(java.io.File)
For a more memory-efficient approach, see LineIterator in the same package.
--
Jim Janney
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
Shortest way to read all lines (one by one) from a text file? rob@wenger.net (Robin Wenger) - 2011-02-11 08:20 +0000 Re: Shortest way to read all lines (one by one) from a text file? Jim Janney <jjanney@shell.xmission.com> - 2011-02-11 08:23 -0700 Re: Shortest way to read all lines (one by one) from a text file? Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-02-11 17:01 +0800 Re: Shortest way to read all lines (one by one) from a text file? Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2011-02-11 22:15 -0800
csiph-web