FileStream Constructor (String, FileMode, FileSystemRights, FileShare, Int32, FileOptions, FileSecurity)
Imports System
Imports System.IO
Imports System.Text
Imports System.Security.AccessControl
Module FileStreamExample
Sub Main()
Try
Dim messageByte As Byte() = Encoding.ASCII.GetBytes("Here is some data.")
Dim fs As New FileSecurity()
fs.AddAccessRule(New FileSystemAccessRule("DOMAINNAME\AccountName", FileSystemRights.ReadData, AccessControlType.Allow))
Dim fWrite As New FileStream("test.txt", FileMode.Create, FileSystemRights.Modify, FileShare.None, 8, FileOptions.None, fs)
fWrite.WriteByte(System.Convert.ToByte(messageByte.Length))
fWrite.Write(messageByte, 0, messageByte.Length)
fWrite.Close()
Dim fRead As New FileStream("test.txt", FileMode.Open)
Dim length As Integer = Fix(fRead.ReadByte())
Dim readBytes(length) As Byte
fRead.Read(readBytes, 0, readBytes.Length)
fRead.Close()
Console.WriteLine(Encoding.ASCII.GetString(readBytes))
Catch e As Exception
Console.WriteLine(e)
End Try
End Sub
End Module
Related examples in the same category