Returns String value that contains characters from a file opened in Input or Binary mode. The My feature gives you better productivity and performance in file I/O operations than InputString. For more information, see FileSystem.
Assembly: Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)
- Type: System.Int32
Required. Any valid file number.
- Type: System.Int32
Required. Any valid numeric expression specifying the number of characters to read.
Return ValueType: System.String
Returns String value that contains characters from a file opened in Input or Binary mode. The My feature gives you better productivity and performance in file I/O operations than InputString.
The InputString function is provided for backward compatibility and may affect performance. For non-legacy applications, the My.Computer.FileSystem object provides better performance. For more information, see File Access with Visual Basic.
Data read with the InputString function is usually written to a file by using Print or FilePut. Use this function only with files opened in Input or Binary mode.
Unlike the Input function, the InputString function returns all the characters it reads. This includes commas, carriage returns, line feeds, quotation marks, and leading spaces.
With files opened for Binary access, an attempt to read through the file by using the InputString function until EOF returns True generates an error. Use the LOF and Loc functions instead of EOF when you read binary files by using InputString, or use FileGet when you use the EOF function.
When reading from files, do not make security decisions about the contents of the file based on the file name extension. For example, a file named Form1.vb may not be a Visual Basic source file.
This example uses the InputString function to read one character at a time from a file and print it to the Output window. This example assumes that MyFile is a text file that has several lines of sample data.
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.