aspose file tools*
The moose likes I/O and Streams and the fly likes Best way to open a text file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Best way to open a text file" Watch "Best way to open a text file" New topic
Author

Best way to open a text file

Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 828
As the subject goes, what's the optimum way to open a text file with multiple, varying length lines for processing. Basically the lines in the file have values that are tab-delimited and I want to read the values in and assign them to different fields on a HTML form. Thanks.

Rob
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Look through the JavaDoc for FileReader and BufferedReader to read a file one line at a time. Look at String.split (JDK 1.4+) or StringTokenizer to break up the tab delimited fields. If you're feeling adventurous and you know some RegEx, look at Scanner (JDK 5+) to do both at once. Let us know how it goes!


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Actually if you're using JDK 5, Scanner is a good choice even if you don't know regex (yet). You can just create one and use the nextLine() method to read lines, much like you would use readLine() in a BufferedReader. But Scanner gives you a lot more options than BufferedReader does.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Best way to open a text file