Results 1 to 4 of 4
Thread: Buffered Reader problem
- 07-30-2009, 05:57 PM #1
Member
- Join Date
- Jul 2009
- Posts
- 2
- Rep Power
- 0
Buffered Reader problem
hi,
I am trying to read a file twice. The sample code is as follows:
Java Code:BufferredReader fileReader = new BufferedReader(new FileReader("abc.txt")); if(CiscoTraceRouteParser.canParse(fileReader)) { // Do Something } else if(JuniperTraceRouteParser.canParse(fileReader)) { // Do something else }
The canParse methods are of the type
The problem is if the first 'if' check fails, then we have to do the second if check which when has to readLine from the first line of the same file. This is failing. I tried to mark and then do a reset , but not able to get the pointer reset to the begining of the file second time around.Java Code:public static boolean canParse(BufferredReader fileReader) { while((line == fileReader.readLine()) != null) { if(some condition satisfied for the line) return true; } return false; }
Please help me out with this. Thansk!
PradeepLast edited by Fubarable; 07-30-2009 at 06:26 PM. Reason: Code tags added for readability
- 07-30-2009, 07:01 PM #2
Member
- Join Date
- Jul 2009
- Posts
- 6
- Rep Power
- 0
i think making some changes as in the following solves the problem:
Java Code:FileReader fileReader = new FileReader("abc.txt"); if(CiscoTraceRouteParser.canParse(new BufferedReader(fileReader))) { // Do Something } else if(JuniperTraceRouteParser.canParse(new BufferedReader(fileReader))) { // Do something else }
- 07-30-2009, 08:15 PM #3
Member
- Join Date
- Jul 2009
- Posts
- 2
- Rep Power
- 0
Thanks pushdown!
It solves the problem. Looks like I cant use the same bufferredreader every time in the loop. Will use this for the time being.
Regards,
Pradeep
- 07-31-2009, 11:37 AM #4
Member
- Join Date
- Jul 2009
- Posts
- 6
- Rep Power
- 0
If BufferReader had a method which can be move the cursor to the beginning, then we could use same BufferReader object with moving cursor beginning, just before calling canParse func. but unfortunately it has not such method. Thus, we have to renew the reader object so that it can provide reading from beginning.
Similar Threads
-
Please solve the problem related to PDf reader
By kavithaprabhaker in forum New To JavaReplies: 5Last Post: 11-23-2011, 10:08 AM -
Buffered Reader Exception
By hitmen in forum New To JavaReplies: 6Last Post: 01-07-2009, 11:14 AM -
Unable to draw buffered image
By pedjasmek in forum Java 2DReplies: 7Last Post: 08-08-2008, 03:49 PM -
FileReader / Buffered Reader
By sepaht in forum New To JavaReplies: 9Last Post: 07-10-2008, 08:05 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks