• Post Reply Bookmark Topic Watch Topic
  • New Topic

flushing /closing buffers?  RSS feed

 
Drake Silver
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi..
I have a small problem.
In my program, when I open a file then
process that data...it works, but, if I then go
and open another file, and process this new files data, the old files data is what shows up.
I'm guessing I need to fluch the old data out of the buffer...
but how.
I can't use .flush on bufferedReader or FileReader, it won't give me that option.
I tried using .close but I don't think it did much.
BTW:
what's the diff between close and flush?
Am I right is saying that I need to get rid of the old data in the Buffer for the new data to replace its memory space?
P.S
The only time i've seen flush used is in Writing to files...?
 
eric sato
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi DrakeSilver,
Flush is flushing the buffer content to a file. And you can use .flush() by your file handler. Not your IO objects.
.close() is use when finish to write a file. It allows others user(maybe) to edit a file. This is because when you open a file, no one allow to edit the same file unless you explicitly close it.
Hope this will help
Cheers
sato
 
Drake Silver
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok. that makes sense.
But then how do you get rid of the data in the buffer?

I mean, after the file opened is closed, and the data is written to a file, shouldn't the buffer be cleared out of a files contents. And does Java take care of this with the garbage collector, or do I manually have to clear the buffer?
thanks for the response, it helped clear some of my confusion up.
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Er... What do you mean by 'the buffer'? You can't use the same FileReader or FileInputStream to read multiple different files. Are you talking about your own buffer? That would be something like
byte[] buffer = new byte[1024];
in.read(buffer);
If that's the case and you're find old data, it may be a sign that you haven't been keeping good track of how many bytes have been read.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!