Read and Write to a Newly Created Data File : FileStream « File Directory « VB.Net






Read and Write to a Newly Created Data File

 
Imports System
Imports System.IO

Class MyStream
    
    Public Shared Sub Main()
        Using fs As New FileStream("Test.data", FileMode.CreateNew)
            Using w As New BinaryWriter(fs)
                For i As Integer = 0 To 10
                    w.Write(i)
                Next
            End Using
        End Using
        Using fs As New FileStream("Test.data", FileMode.Open, FileAccess.Read)
            Using r As New BinaryReader(fs)
                For i As Integer = 0 To 10
                    Console.WriteLine(r.ReadInt32())
                Next
            End Using
        End Using
    End Sub
End Class

   
  








Related examples in the same category

1.Use FileStream to store and read fileUse FileStream to store and read file
2.Read and Write to a Newly Created Data File
3.FileStream Class
4.Create FileStream with FileMode.Append, FileAccess.Write, FileShare.Write
5.FileStream Constructor (String, FileMode, FileSystemRights, FileShare, Int32, FileOptions, FileSecurity)
6.FileStream.CanRead Property gets a value indicating whether the current stream supports reading.
7.FileStream.CanSeek Property gets a value indicating whether the current stream supports seeking.
8.FileStream.CanWrite Property gets a value indicating whether the current stream supports writing.
9.FileStream.CanRead And FileStream.CanWrite
10.FileStream.Seek Method sets the current position of this stream to the given value.
11.FileStream Class Exposes a Stream around a file
12.FileStream.CanRead Property tells whether the current stream supports reading.
13.FileStream.CanSeek Property tells whether the current stream supports seeking.
14.FileStream.CanWrite Property tells whether the current stream supports writing.
15.FileStream.Read Method Reads a block of bytes
16.FileStream.ReadByte Method Reads a byte from the file
17.FileStream.Seek Method Sets the current position of this stream to the given value.