Use FileStream to store and read file : FileStream « File Directory « VB.Net






Use FileStream to store and read file

Use FileStream to store and read file
 
Imports System
Imports System.IO

Public Class MainClass

  Shared Sub Main()

    Dim i As Integer
    Dim theBytes(255) As Byte
    For i = 0 To 255
      theBytes(i) = CByte(i)
    Next
    Dim myFileStream As FileStream
    Try
      myFileStream = New FileStream("test.txt", FileMode.OpenOrCreate, FileAccess.Write)
      myFileStream.Write(theBytes, 0, 256)
    Finally
      If Not (myFileStream Is Nothing) Then myFileStream.Close()
    End Try


    Dim theFile As FileStream
    Try
      theFile = New FileStream("test.txt",FileMode.Open, FileAccess.Read)
      For i = 0 To (theFile.Length - 1)
        Console.Write(theFile.ReadByte)
      Next
    Catch e As Exception
      Throw e
    Finally
      If Not (theFile Is Nothing) Then theFile.Close()
    End Try
  End Sub
  
End Class


           
         
  








Related examples in the same category

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