Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes I/O and Streams and the fly likes Reading text files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Reading text files" Watch "Reading text files" New topic

Reading text files

mike vessey

Joined: Nov 09, 2002
Posts: 2
I am new to Java and am trying to write a piece of code which will read from a text file and extract words ending with a question mark. I would like to be able to move forwards and backwards through a file.
I've tried using FileReader but the read method only goes forwards. How can I then read the previous character?
Could I read the whole file into a String and then use that instead?
David Weitzman
Ranch Hand

Joined: Jul 27, 2001
Posts: 1365
It sounds like you don't really need the full power of random access (although it is an option -- see RandomAccessFile or in Java 1.4 FileChannel).
If you're extracting words, the first (simplest) solution that comes to mind first is to read in the file line by line and then process each line as a String.
Have you tried LearnNowOnline?
subject: Reading text files