Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

BufferedReader problem  RSS feed

 
James Basller
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

My question is regarding BufferedReader. It's readLine() method reads line by line file. Now, my problem is that I have a file that looks like below,
31-Apr-2008
ABC
DEF
AAA
SSS
DDDD
1-June-2008
QQQ
EEEE
RRRRR
TTTTTT
2-June-2008
aaa
adfdfd
erere

and so on...........


Now, I want to separate records when the date comes while reading. So, is it possible with bufferedReader. I have tried but to check next line is date or not we need to call readLine() method and once it's done I can't get it back means here my records are becoming combinations of (date & data). So, for first record it's ok but when I tried to read lines 1-June-2008 will be of second record and I have already read that line so I can't get it back. Is there any way to get that line again? Because I need it back for making records.....

I think for my problem I need to check in advance what will be the next line without readLine() method OR if readLine() method is called I need to go back for the previous line.

Can anybody explain me how can I achieve my target?

Thanks!!!
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can write something like this:



You have to write "isNotADate()", "doWhateverWithTheNonDateLines()", and "doneProcessingRecord()" yourself, of course.
 
Moojid Hamid
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Certainly what Ernest is suggesting is a better approach. Alternatively you can use mark() and reset() as a quick and dirty hack.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!