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


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

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

Path csiph.com!eeepc.pasdenom.info!news.pasdenom.info!news.dougwise.org!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
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 Fri, 11 Feb 2011 08:23:15 -0700
Organization As little as possible
Lines 21
Message-ID <2pk4h6oasc.fsf@shell.xmission.com> (permalink)
References <4d54f158$0$6975$9b4e6d93@newsspool4.arcor-online.net>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Injection-Info mx03.eternal-september.org; posting-host="wbPfjS3fkCDlyt5G4K4SyA"; logging-data="7176"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+RsuYKXAXOPZFhIkTqeAwj"
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)
Cancel-Lock sha1:rlHOsOklAaoD4Mbg9P2sTAprSdo= sha1:YDLX8F9bocAfaqpywLr4gbjo/nY=
Xref csiph.com comp.lang.java.programmer:26030

Show key headers only | View raw


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 | 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