VB.Net/File Directory/File Lock — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 16:40, 26 мая 2010
Lock and unlock a file
Imports System.IO
Module Module1
Sub Main()
Dim FileSt As FileStream = New FileStream("test.dat", FileMode.Create, FileAccess.Write, FileShare.Write)
Try
FileSt.Lock(0, 100)
Console.WriteLine("Locked")
Catch Ex As Exception
Console.WriteLine(Ex.Message)
End Try
Try
FileSt.Unlock(0, 100)
Console.WriteLine("Unlocked")
Catch Ex As Exception
Console.WriteLine(Ex.Message)
End Try
Dim Values As Byte()
Values = New Byte() {1, 2, 3, 4, 5}
Try
FileSt.Seek(0, SeekOrigin.Begin)
FileSt.Write(Values, 0, 5)
Console.WriteLine("Successfully updated file")
Catch Ex As Exception
Console.WriteLine(Ex.Message)
End Try
End Sub
End Module