private void button5_Click(object sender, System.EventArgs e)
{
// Open an already-existing file for read-only. Allow other
// processes to open the file while we have it open.
FileStream fs = 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.
byte[] byteArray = new byte[100];
int numBytesRead = fs.Read(byteArray, 0, 100);
fs.Close();
}
{
// Open an already-existing file for read-only. Allow other
// processes to open the file while we have it open.
FileStream fs = 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.
byte[] byteArray = new byte[100];
int numBytesRead = fs.Read(byteArray, 0, 100);
fs.Close();
}
文章標籤
全站熱搜
