File stream operations in

By: Issac  

The FileStream class allows us to move data to and from the stream as arrays of bytes, a filestream actually symbolizes a a file in a system. We operate File using FileMode in FileStream Class

Some of the FileModes are as Follows : 

FileMode.Append: It opens and appends to a file, if the file does not exist, it creates a new file
FileMode.Create: Creates a new file, if the file already exists it will appends to it.
FileMode.CreateNew: Creates a new file, if the file exists it throws an exception.
FileMode.Open: Opens an existing file

How to create a file using VB.NET FileStream? 

The following example shows, how to write in a file using FileStream.

Imports System.IO
Imports System.Text
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim wFile As System.IO.FileStream
Dim byteData() As Byte
byteData = Encoding.ASCII.GetBytes("FileStream Test1")
wFile = New FileStream("streamtest.txt", FileMode.Append)
wFile.Write(byteData, 0, byteData.Length)
Catch ex As IOException
End Try
End Sub
End Class

When we execute the program, it creates a new File and writes the content to it.

Archived Comments

Most Viewed Articles (in )

Latest Articles (in

Comment on this tutorial