Re: FileStream questions

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Thanks for the tip Pete, I did a bit of searching and now I have it working.
My problem was not reading the bool value of what I was putting in,
so everything looked wrong when the values came out.

When using the same scenario using BinaryWriter and FileStream, do you
know how to click on a treenode and have many records for that node
display in a listview? I can't even begin to think of how to do that.

know how to get one record to display, but if you have maybe 20
records attached to one node, I just don't know.

John

"Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx> wrote in message
news:op.t7kh91n78jd0ej@xxxxxxxxxxxxxxxxxxxxxxx
On Wed, 05 Mar 2008 14:27:07 -0800, John <johnrogers2345@xxxxxxx> wrote:

[...]
1. How do you read the file from beginning to end, reading from the first
record until there is no more records?

You're writing strings, so you need to use BinaryReader.ReadString().
Looking at the docs, it appears to me that the ReadString() method will
throw an exception once you've reached the end of the stream.

2. When saving to the file, do you always have to replace the entire
file,
or can you just update the information whenever any single item has
changed?

You do not have to replace the entire file. However, that's not to say
that it'd be easy to replace individual chunks of data within the file.
The file is still a stream of bytes, even if you wrap the FileStream that
opened it with a BinaryWriter. You can replace bytes, but there's no
facility to insert or delete bytes. So unless you're trying to replace a
section of the file with an identical length section, you need to rewrite
all of the data after that section, at a minimum, to adjust for the change
in size of the chunk you're modifying.

It's not the sort of thing you'd want to do over and over for large files.

Pete


.



Relevant Pages

  • Re: FileStream questions
    ... How do you read the file from beginning to end, reading from the first ... You're writing strings, so you need to use BinaryReader.ReadString. ... it appears to me that the ReadStringmethod will throw an exception once you've reached the end of the stream. ... that's not to say that it'd be easy to replace individual chunks of data within the file. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Reading Simple Flatfiles with a COBOL Mindset
    ... I am new to C and old to COBOL ... > in with respect to reading a simple file - one record at a time. ... stream and impose your interpretation on them: ... there are text streams and binary streams. ...
    (comp.lang.c)
  • Re: Reading from standard input
    ... I finally understood the concept of '-' stream. ... I am learning perl scripting and was reading an online tutorial where i ... Can somebody explain me why reading from the standard input ...
    (comp.lang.perl.misc)
  • StreamReader.Read blocking?
    ... spawn threads that handle the reading of the streams by placing the stream ... Debug.WriteLine("Started reading standard output."); ... characters are read, or the end of the file is reached. ... About ReadBlock(), MSDN says: The method blocks until either count ...
    (microsoft.public.dotnet.framework)
  • StreamReader.Read blocking?
    ... spawn threads that handle the reading of the streams by placing the stream ... Debug.WriteLine("Started reading standard output."); ... characters are read, or the end of the file is reached. ... About ReadBlock(), MSDN says: The method blocks until either count ...
    (microsoft.public.dotnet.framework)