FileSystem.InputString(Int32, Int32) 方法

定义

返回String一个值,该值包含打开或Binary模式下的文件中的Input字符。 此功能 My 可让你在文件 I/O 操作 InputString中提高工作效率和性能。 有关详细信息,请参阅 FileSystem

public:
 static System::String ^ InputString(int FileNumber, int CharCount);
public static string InputString(int FileNumber, int CharCount);
static member InputString : int * int -> string
Public Function InputString (FileNumber As Integer, CharCount As Integer) As String

参数

FileNumber
Int32

必填。 任何有效的文件编号。

CharCount
Int32

必填。 指定要读取的字符数的任何有效数值表达式。

返回

一个字符串,其中包含在 InputBinary 模式下打开的文件中的字符。 此功能 My 可让你在文件 I/O 操作 InputString中提高工作效率和性能。

例外

FileNumber 不存在。

CharCount < 0 或 > 214。

示例

此示例使用 InputString 函数从文件一次读取一个字符并将其打印到 Output 窗口。 此示例假定 MyFile 是包含多行示例数据的文本文件。

Dim oneChar As String
' Open file.
FileOpen(1, "MYFILE.TXT", OpenMode.Input)
' Loop until end of file.
While Not EOF(1)
    ' Get one character.
    oneChar = (InputString(1, 1))
    ' Print to the output window.
    System.Console.Out.WriteLine(oneChar)
End While
FileClose(1)

注解

InputString 函数用于向后兼容性,可能会影响性能。 对于非旧应用程序,该 My.Computer.FileSystem 对象可提供更好的性能。 有关详细信息,请参阅 File Access with Visual Basic

使用 InputString 函数读取的数据通常通过使用 PrintFilePut写入文件。 仅在打开 Input 的文件或 Binary 模式下使用此函数。

与函数 Input 不同,该 InputString 函数返回读取的所有字符。 这包括逗号、回车符、换行符、引号和前导空格。

打开文件以供 Binary 访问时,尝试使用 InputString 函数读取文件,直到 EOF 返回 True 时会生成错误。 LOF使用和Loc函数,而不是EOF在使用InputString函数读取二进制文件时使用FileGet或使用该EOF函数时使用。

注释

从文件读取时,不要根据文件扩展名对文件的内容做出安全决策。 例如,名为Form1.vb的文件可能不是Visual Basic源文件。

适用于

另请参阅