File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes File pointer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "File pointer" Watch "File pointer" New topic
Author

File pointer

Arun Boraiah
Ranch Hand

Joined: Nov 28, 2001
Posts: 233
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


Sharing is learning
Wilfried LAURENT
Ranch Hand

Joined: Jul 13, 2001
Posts: 269
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

Joined: Nov 28, 2001
Posts: 233
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
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
A BufferedReader would also allow you to read one line at a time.
Perhaps RandomAccessFile is more what you'd like to use.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File pointer