By: Issac Emailed: 1758 times Printed: 2452 times
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.
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
When we execute the program, it creates a new File and writes the content to it.
Be the first one to add a comment
Most Viewed Articles (in VB.net )
Most Emailed Articles (in VB.net)