You must use BINARY reader/writer object and also specify the field-type of the data being sent to the write-stream and the same goes for data being read in the reader from the stream.
Dim filename As String = "c:\temp\binfile.bin"
Dim writer As BinaryWriter
Dim reader As BinaryReader
Dim tmpStringData As String
Dim tmpByteData As Byte
Dim tmpCharData As Char
Dim tempIntData as Integer
Dim tempBoolData as Boolean
'
writer = New BinaryWriter(File.Open(filename, FileMode.Append))
Using writer
writer.Write("apple")
'writer.Write(YourByteDataHere) 'byte
'writer.Write(YourCharHere) 'char
'writer.Write(1.31459) 'single
'writer.Write(100) 'integer
'writer.Write(False) 'boolean
End Using
writer.Close()
'
If (File.Exists(filename)) Then
reader = New BinaryReader(File.Open(filename, FileMode.Open))
Using reader
tmpStringData = reader.ReadString()
'tempByteData = reader.ReadByte()
'tempCharData = reader.ReadChar()
'tempSingleData = reader.ReadSingle()
'tempIntData = reader.ReadInt32()
'tempBoolData = reader.ReadBoolean()
End Using
reader.Close()
End If
I used ReadString() method to write the string "apple"
You could use the chr code for a character or byte if you wish, in which case you must use ReadByte() or ReadChar() or ReadInt() depending on how you sent it to the stream (as a byte, char or integer)
So the file size is 6 bytes 1 for its own internal use by the file stream handler and 5 for your 'apple'
And if you saved it as char or byte I would think its 5 bytes used and 1k long
And if you saved it as integer I would think its 10 bytes used and 1k long
reference: http://msdn.microsoft.com/en-us/library/system.io.binarywriter.aspx