FileSystem.Seek 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回一个 Long 指定使用 FileOpen 函数打开的文件中的当前读/写位置,或设置使用 FileOpen 函数打开的文件中下一个读/写操作的位置。 此功能 My 可让你在文件 I/O 操作 Seek中提高工作效率和性能。 有关详细信息,请参阅 FileSystem。
重载
| 名称 | 说明 |
|---|---|
| Seek(Int32) |
返回一个 |
| Seek(Int32, Int64) |
返回一个 |
Seek(Int32)
- Source:
- FileSystem.vb
- Source:
- FileSystem.vb
- Source:
- FileSystem.vb
- Source:
- FileSystem.vb
- Source:
- FileSystem.vb
返回一个 Long 指定使用 FileOpen 函数打开的文件中的当前读/写位置,或设置使用 FileOpen 函数打开的文件中下一个读/写操作的位置。 此功能 My 可让你在文件 I/O 操作 Seek中提高工作效率和性能。 有关详细信息,请参阅 FileSystem。
public:
static long Seek(int FileNumber);
public static long Seek(int FileNumber);
static member Seek : int -> int64
Public Function Seek (FileNumber As Integer) As Long
参数
- FileNumber
- Int32
必填。 包含有效文件编号的一个 Integer 。
返回
指定 Long 使用 FileOpen 函数打开的文件中的当前读/写位置,或设置使用 FileOpen 函数打开的文件中下一个读/写操作的位置。
例外
文件模式无效。
示例
此示例使用 Seek 函数返回当前文件位置。 该示例假定 TestFile 是包含结构 Record记录的文件。
Structure Record ' Define user-defined type.
Dim ID As Integer
Dim Name As String
End Structure
对于在 Random 模式下打开的文件, Seek 返回下一条记录的数目。
FileOpen(1, "TESTFILE", OpenMode.Random)
Do While Not EOF(1)
WriteLine(1, Seek(1)) ' Write record number.
FileGet(1, MyRecord, -1) ' Read next record.
Loop
FileClose(1)
对于以模式以外的 Random 模式打开的文件, Seek 返回下一个操作所在的字节位置。 假定 TestFile 是包含多行文本的文件。
' Report character position at beginning of each line.
Dim TextLine As String
FileOpen(1, "TESTFILE", OpenMode.Input) ' Open file for reading.
While Not EOF(1)
' Read next line.
TextLine = LineInput(1)
' Position of next line.
MsgBox(Seek(1))
End While
FileClose(1)
此示例使用 Seek 函数设置文件中下一次读取或写入的位置。
对于以模式以外的 Random 模式打开的文件, Seek 请设置下一个操作所在的字节位置。 假定 TestFile 是包含多行文本的文件。
Dim someText As String = "This is a test string."
' Open file for output.
FileOpen(1, "TESTFILE", OpenMode.Input)
' Move to the third character.
Seek(1, 3)
Input(1, someText)
Console.WriteLine(someText)
FileClose(1)
注解
Seek 返回一个介于 1 和 2,147,483,647 之间的值(相当于 2^31 - 1),包括 2^31 - 1。
下面描述了每个文件访问模式的返回值:
| 模式 | 返回值 |
|---|---|
Random |
读取或写入的下一条记录的数目 |
Binary、Input、Output、Append |
下一个操作所在的字节位置。 文件中的第一个字节位于位置 1,第二个字节位于位置 2,依此而行。 |
另请参阅
- FileGet
- Loc(Int32)
- FileOpen(Int32, String, OpenMode, OpenAccess, OpenShare, Int32)
- FilePut
- IOException
从 Visual Basic 写入 Visual Basic
适用于
Seek(Int32, Int64)
- Source:
- FileSystem.vb
- Source:
- FileSystem.vb
- Source:
- FileSystem.vb
- Source:
- FileSystem.vb
- Source:
- FileSystem.vb
返回一个 Long 指定使用 FileOpen 函数打开的文件中的当前读/写位置,或设置使用 FileOpen 函数打开的文件中下一个读/写操作的位置。 此功能 My 可让你在文件 I/O 操作 Seek中提高工作效率和性能。 有关详细信息,请参阅 FileSystem。
public:
static void Seek(int FileNumber, long Position);
public static void Seek(int FileNumber, long Position);
static member Seek : int * int64 -> unit
Public Sub Seek (FileNumber As Integer, Position As Long)
参数
- FileNumber
- Int32
必填。 包含有效文件编号的一个 Integer 。
- Position
- Int64
必填。 范围 1-2,147,483,647(含)中的数字,指示下一次读取/写入操作应发生的位置。
例外
文件模式无效。
示例
此示例使用 Seek 函数返回当前文件位置。 该示例假定 TestFile 是包含结构 Record记录的文件。
Structure Record ' Define user-defined type.
Dim ID As Integer
Dim Name As String
End Structure
对于在 Random 模式下打开的文件, Seek 返回下一条记录的数目。
FileOpen(1, "TESTFILE", OpenMode.Random)
Do While Not EOF(1)
WriteLine(1, Seek(1)) ' Write record number.
FileGet(1, MyRecord, -1) ' Read next record.
Loop
FileClose(1)
对于以模式以外的 Random 模式打开的文件, Seek 返回下一个操作所在的字节位置。 假定 TestFile 是包含多行文本的文件。
' Report character position at beginning of each line.
Dim TextLine As String
FileOpen(1, "TESTFILE", OpenMode.Input) ' Open file for reading.
While Not EOF(1)
' Read next line.
TextLine = LineInput(1)
' Position of next line.
MsgBox(Seek(1))
End While
FileClose(1)
此示例使用 Seek 函数设置文件中下一次读取或写入的位置。
对于以模式以外的 Random 模式打开的文件, Seek 请设置下一个操作所在的字节位置。 假定 TestFile 是包含多行文本的文件。
Dim someText As String = "This is a test string."
' Open file for output.
FileOpen(1, "TESTFILE", OpenMode.Input)
' Move to the third character.
Seek(1, 3)
Input(1, someText)
Console.WriteLine(someText)
FileClose(1)
注解
Seek 返回一个介于 1 和 2,147,483,647 之间的值(相当于 2^31 - 1),包括 2^31 - 1。
下面描述了每个文件访问模式的返回值:
| 模式 | 返回值 |
|---|---|
Random |
读取或写入的下一条记录的数目 |
Binary、Input、Output、Append |
下一个操作所在的字节位置。 文件中的第一个字节位于位置 1,第二个字节位于位置 2,依此而行。 |
另请参阅
- FileGet
- Loc(Int32)
- FileOpen(Int32, String, OpenMode, OpenAccess, OpenShare, Int32)
- FilePut
- IOException
从 Visual Basic 写入 Visual Basic