Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reading in files

 
kevin schmidt
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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.
Kevin
 
timothy zimmerman
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic