From Xojo Documentation
Opens the passed FolderItem as a binary stream. The readwrite parameter controls whether the file is open for read/write operations or read-only. When True, you can read and write to the file. When False you can only read from the file. The default is False. If an error occurs, an IOException is raised.
Call Open using the syntax for a shared method.
This code reads a text file called "Whole File" and displays it in a TextArea. There is no attempt to parse the contents of the file.
If f <> Nil Then
Dim bs As BinaryStream = BinaryStream.Open(f, False) // Open as read-only
// read the whole binaryStream
TextArea1.Text = bs.Read(bs.Length)
Catch e As IOException
// something went wrong when opening the file. This is where you would handle the error
// if appropriate
This code reads each pair of bytes from a file and writes them in reverse order to a new file. The user chooses the source file using the Open-file dialog box and saves the new file using the Save as dialog box.
If inputFile <> Nil Then
// Open as read-only
Dim inputStream As BinaryStream = BinaryStream.Open(inputFile, False)
inputStream.LittleEndian = True
Dim outputFile As FolderItem = GetSaveFolderItem("", "")
If outputFile <> Nil Then
// Open as read-write
Dim outputStream As BinaryStream = BinaryStream.Create(outputFile, True)
Do Until inputStream.EOF