• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading text files

 
mike vessey
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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?
Thanks,
Mike
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic