The Artima Developer Community
Sponsored Link

Java Buzz Forum
FileParser.eachLine: Learning from other languages

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
dion

Posts: 5028
Nickname: dion
Registered: Feb, 2003

Dion Almaer is the Editor-in-Chief for TheServerSide.com, and is an enterprise Java evangelist
FileParser.eachLine: Learning from other languages Posted: Jan 24, 2005 6:47 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by dion.
Original Post: FileParser.eachLine: Learning from other languages
Feed Title: techno.blog(Dion)
Feed URL: http://feeds.feedburner.com/dion
Feed Description: blogging about life the universe and everything tech
Latest Java Buzz Posts
Latest Java Buzz Posts by dion
Latest Posts From techno.blog(Dion)

Advertisement
At one time, if I had to write some code which was to loop through a file and do something with the contents, I would have thought: - open the file - while (there is a line) - get line - do something with line - close up resources And, I would make sure that all of the IO exceptions are handled correctly, that the resources are closed nicely in a finally { } etc etc. However, since I get to code in other environments (Ruby, Groovy, etc) I now use a simple utility to do this kind of task. Here is the most simple test case which uses the FileParser utility: public void testSimpleCommand() { FileParser.eachLine(sampleFileLineReader, new LineCommand() { public void useLine(String lineContents) { assertEquals(sampleFileLine, lineContents); } }); } Now the code that handles file IO is in one place (FileParser) and my application code doesn't have to worry about it! Compare this to the Groovy: new File(inputFile).eachLine { | line | ....... }

Read: FileParser.eachLine: Learning from other languages

Topic: Arrays.asList("Rod", "Jane", "Freddy"); Previous Topic   Next Topic Topic: Mind Wide Open

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use