• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

reading in files

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic