[quote=490794:@Clifford Coulter]Darn, I’m back to where I first started. I entered the code into my program and “Menu Prefs” text file is still not showing any data. No errors. I thought I could enter integers or strings although they would be seen in a text editor as binary info. I see nothing.
When I used TextStream I was able to write to the same “Menu Prefs” file so I would think it’s a writable file.[/quote]
This is the main difference between a TextInput/TextOutput stream and a BinaryStream: the Text version, as its name implies, writes everything as text data to the file (meaning, 1234 will be 1234 as text; specifically, your text file would be made of 4 bytes: 49, 50, 51, 52 (with a decimal view). 49 is the ascii number for the text 1, etc.). So, when your text editor opens the file with those 4 bytes, it converts 49, 50, 51 and 52 as characters (resulting in 1234).
On the other hand, the BinaryStream uses no conversion, it just writes the bytes/numbers, etc. you told it. If you write the same value (1234) using b.WriteInt32 1234, you don’t write characters (1234 is a number here, not a string), you write 1234 as an int32 (which means an integer of 4 bytes (4x8=32)). Therefore, your file, with only 1234 written as an int32, would have these bytes (as little endian; disregard this information for now if you don’t know what it means): 0 0 4 210 (still viewed in decimal). If you do the math, you have 21016^0+416^1+016^2+016^3=1234. The first two 0 are here for padding (remember: an int32 is 4 bytes, always).
If you compare the bytes (e.g. with HexEdit) of both versions (“1234” using a TextOutputStream and 1234 as an int32 using a BinaryStream), you’d see this (I’m converting as decimal here to stay with the remaining of my explanation, although HexEdit would show you hex values):
Binary (1234): 0 0 4 210 (in hex: 00 00 04 D2)
Text (1234): 49 50 51 52 (in hex: 31 32 33 34)
What it means is that those streams are used for very different purposes. The TextOutputStream writes text files that can be viewed directly by the user. You can only write text there, but they will always consist of text.
The BinaryStream writes whatever kind of data you pass to it, sequentially. If you WriteInt32, you append 4 bytes; if you WriteBoolean, you append 1 bit, etc. All write methods of the BinaryStream, except the plain write have fixed lengths: to read the file back, you read the same sequences (e.g. ReadInt32 would read 4 bytes and return the resulting integer).
If you want to write some strings sequentially in your BinaryStream, you can either use b.WritePString (limited to 255 characters, the first byte being the length of the actual text; additional characters would be truncated) or use b.WriteInt32 (length)+b.Write (Text). To read back, you’d use either b.ReadPString or b.Read(b.ReadInt32) for longer strings.
BinaryStreams are usually not intended to be viewed by users (except programmers who can use a hex editor and, carefully, make some changes to the data).
For example, you can open a picture file using a BinaryStream and read its format, chunk by chunk (reading the headers, parameters, etc.). The same reading with a TextInputStream would just return the data as a string (often in a human unreadable form).
Now, the BinaryStream can also write plain string (text files without default encoding), using the b.Write method. In this case, you lose the sequential behaviour.
BinaryStreams can do way much than Text streams can, suitable for all files. On the other hand, Text streams are good for plain text files: you can specify a delimiter (e.g. an end of line) and use WriteLine to write your text+the delimiter; writing things like boolean, colors, or numbers, however, require conversions to/from strings, unlike the BinaryStream way.
Again a lot of information; those streams can be fascinating ?.