The moose likes Beginning Java and the fly likes reading in files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "reading in files" Watch "reading in files" New topic

reading in files

kevin schmidt
Ranch Hand

Joined: Aug 24, 2001
Posts: 85
I'm reading a file in my program, but now all the information I was retrieving from the beginning of the file is now at the end of the file. The files are rather big and take too much space to store in a string. This is the line I use to read the file:
BufferedReader inPDF = new BufferedReader(new FileReader(fName)
Is there any way in java to start reading the file from the end and not the start? I know whereabouts I want to start reading the file. Every file has the same information at the end of it. I just need to know how to skip to the end. One more thing. Each file has a "(Rich)" right before I want to store information. How would I search for "(Rich)"? TIA.
timothy zimmerman
Ranch Hand

Joined: Jun 26, 2001
Posts: 149
FileReader has a method called skip(long n) which allows you to skip n bytes of data.
BufferedReader has a method called readLine(). You could use this method within a loop but this still read each line so that may not be what you want.
There is also a class called LineReader which would allow you to set the line number ( setLineNumber(int n) ) os you could jump toward the end of the file that way.
However you do it though I think you will still have to read in a line(s) to see if it contains the word you are looking for but you amy be able to use the above methods to jump ahed in the file, closer to the line you are looking for.
I agree. Here's the link:
subject: reading in files
It's not a secret anymore!