Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Read Random-Access Disk File Seek Read-Only File SharingVB.NET source code showing how to open a disk file for random-access in read-only / share mode. Shows how to seek from file origin, current position, or end of file. Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
' Open an already-existing file for read-only. Allow other
' processes to open the file while we have it open.
Dim fs As New FileStream("test.dat", FileMode.Open, FileAccess.Read, FileShare.Read)
' Set the file pointer to 100 bytes from the beginning.
fs.Seek(100, SeekOrigin.Begin)
' Set the file pointer to the end of file.
' There's no point in doing this when we open the file read-only.
' But if you are opening the file read-write, this may be something
' of interest.
fs.Seek(0, SeekOrigin.End)
' Set the file pointer to 100 bytes beyond the current position.
fs.Seek(100, SeekOrigin.Current)
' Set the file pointer to 100 bytes from the beginning.
fs.Seek(100, SeekOrigin.Begin)
' Read 100 bytes at this position.
Dim byteArray(100) As Byte
Dim numBytesRead As Integer = fs.Read(byteArray, 0, 100)
fs.Close()
End Sub
|
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2007 Chilkat Software, Inc. All Rights Reserved.