This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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
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.
Joined: Nov 28, 2001
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