• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading a text file using BufferedReader.

 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

will open the file and start reading from the beginning.

Since bufReader isn't declared in the function, it seems to be a member (or static variable).
After the first read, it should be valid (until EOF), so you can test it first:
, avoiding reopening when already opened.
 
James Oh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks... I'll try it right now.
 
James Oh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose I have a text file that has these information
"JavaRanch Big Moose 0.1 0.2 01 11 15 Hi|Bye
JavaRanch Big Moose2 0.2 0.5 0.1 44 44 See you later|Come back"
Each line is one record.
I have nextRecod() query that returns the next record, and I implemented like this

nextRecord() throws IOException{
bufReader = new BufferedReader(new FileReader(this.getDataFileName()));
rec.readObject(bufReader);
return new FixFixRecord(rec.name, rec.high, rec.low, rec.close, rec.volume, rec.volChange, rec.priceChange, rec.priceChangePercent, rec.symbol, rec.news);
}

No matter how many times I invoke this method, it returns the first record. It doesn't move to the next record. Do I have to use mark(int readAheadLimit) and reset()? If so how do I give readAheadLimit? Please help. Thank you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!