public Seek ( long offset, SeekOrigin origin ) : long | ||
offset | long | |
origin | SeekOrigin | |
return | long |
using System.IO; FileStream fs = new FileStream("myfile.txt", FileMode.Open, FileAccess.ReadWrite); fs.Seek(0, SeekOrigin.Begin); // set the cursor to the beginning of the file
using System.IO; FileStream fs = new FileStream("myfile.txt", FileMode.Open, FileAccess.ReadWrite); fs.Seek(10, SeekOrigin.Current); // move the cursor 10 bytes forward from its current positionIn this example, we create a FileStream object for a file named "myfile.txt" and open it for reading and writing. We then call the Seek method and pass in a value of 10 for the offset parameter, which tells the method to move the cursor 10 bytes forward from its current position. The SeekOrigin.Current parameter specifies that we want to move relative to the current position. Package library: System.IO.FileSystem Overall, the System.IO namespace provides types that allow you to work with files and directories, and the FileStream class is used to read from and write to a file. The Seek method is part of the FileStream class, which is included in the System.IO.FileSystem package.