Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #26047

Re: Shortest way to read all lines (one by one) from a text file?

Date 2011-02-11 17:01 +0800
From Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com>
Newsgroups comp.lang.java.programmer
Subject Re: Shortest way to read all lines (one by one) from a text file?
References <4d54f158$0$6975$9b4e6d93@newsspool4.arcor-online.net>
Message-ID <c_CdnSN0wqBIZ8nQnZ2dnUVZ_jqdnZ2d@posted.palinacquisition> (permalink)

Show all headers | View raw


On 2/11/11 4:20 PM, Robin Wenger wrote:
> 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?

Well, a BufferedReader is a good way to read a line at a time. It would 
be trivial to wrap that in an Iterable implementation so that you could 
use the syntax above.

Pete

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

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