FileSystem.InputString(Int32, Int32) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
回傳String包含在或InputBinary模式中開啟檔案的字元的值。 這個 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
必須的。 任何有效數值表達式,指定要讀取的字元數。
傳回
包含在 Input 或 Binary 模式中開啟的檔案字元的字串。 這個 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 提供更好的效能。 欲了解更多資訊,請參閱檔案存取Visual Basic。
使用該 InputString 函式讀取的資料通常會透過使用 Print 或 FilePut寫入檔案。 此功能僅在檔案開啟於 Input 或 Binary 模式時使用。
與函 Input 式不同的是,函 InputString 式會回傳它讀取的所有字元。 這包括逗號、回車、換行、引號和導引空格。
當檔案開放存取 Binary 時,嘗試使用 InputString 該函式 EOF 讀取檔案直到返回 True 會產生錯誤。 用 LOF and Loc 函數代替EOF讀取二進位檔時的 ,或InputString用函式時EOF用 FileGet 。
備註
讀取檔案時,不要根據副檔名來判斷檔案內容的安全。 例如,名為 Form1.vb 的檔案可能不是Visual Basic原始碼檔案。
適用於
另請參閱
- Input
- 使用 Visual Basic 進行檔案存取
如何:使用 Streamwriter (Visual Basic) 如何:在 Visual Basic