[Help]When reading/writing from a file

10/07/2010 09:17 ryuchetval#1
Hello guys...I have 1 or 2 question about reading and writing from a file.

Reading:
After you have read all the infos from the file you use
filestream.close();
binaryreader.close

I am wondering...if I insert a filstream.flush() (before filestream.close()) does it have any effect? or is it necessary in reading a file? (as the flush() void says it clears all buffers and causes any buffered data to be writen to the file)

Writing:
OK as above I am wondering If it's necessary that a filestream.flush() and a binarywriter.flush() to exist before the files close.

General:
How about disposing (not sure what it is but it says that it releases all the resources being used by the stream)
Would it be any good to insert a filestream/binarywriter/binaryreader.dispose()? If so before or after the file closes?
10/07/2010 09:37 pro4never#2
You can't dispose if it's already closed.

The way I understand it is that it just frees up memory resources and such (which afaik C# will do by itself with garbage collection.. but I could be wrong)

Flush basically just finishes up whatever is happening afaik (so if you're in the middle of writing something then it will finish writing before closing). I could be wrong though. I really don't do much with file I/O
10/07/2010 10:23 ryuchetval#3
Well I already use a GC.Collect() for the resources but it has no effect as far as I see...how about setting the value of the stream/reader/writer to null after it closes...would it have any effect?
10/08/2010 00:53 _tao4229_#4
Close flushes the buffer and also disposes of the object.

[Only registered and activated users can see links. Click Here To Register...]