• 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

File pointer

 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a file which i need to read frist n line and last n number of line only. So is there is any API methods which allow to jump from one line to another with out reading and read only line number which i am interested.
Thanks in advance.
Regards
arun
 
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The closest to what you're looking for in the standard API is
java.io.LineNumberReader.
You can start from there. It has a method readLine() which returns a String. I don't know exactly what you mean by "without reading it".
You may decorate the LineNumberReader interface and add skipLine, getNumberOfLines, readLine(int lineNumber) etc ...
W.
 
Arun Boraiah
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for input Wilfried.

I thought that setLineNumber() will help to solve my problem. But it is not. Might be my
understanding is wrong.
I wrote a simple test method with the following line of code

File oFile= new File("src.txt");
LineNumberReader oLineNoReader = new LineNumberReader(new FileReader(oFile));
oLineNoReader .setLineNumber(3);
System.out.println( "content of 3rd line : " + oLineNoReader.readLine() );

Assume src.txt content is as follows

line 1
line 2
line 3
line 4
...
...

I WANT THE OUTPUT AS FOLLOWS
content of 3rd line : line 3
BUT STILL I AM GETTING OUT PUT AS
content of 3rd line : line 1
Any suggestion please.
Thanks again.
Arun
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A BufferedReader would also allow you to read one line at a time.
Perhaps RandomAccessFile is more what you'd like to use.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic