FileSystem.LineInput Method

Reads a single line from an open sequential file and assigns it to a String variable.

Namespace:  Microsoft.VisualBasic
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

public static string LineInput(
	int FileNumber
)

Parameters

FileNumber
Type: System.Int32

Required. Any valid file number.

Return Value

Type: System.String
Reads a single line from an open sequential file and assigns it to a String variable.

ExceptionCondition
EndOfStreamException

End of file reached.

IOException

FileNumber does not exist.

The LineInput 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 LineInput is usually written to a file by using Print.

Security noteSecurity Note

When reading from files, do not make decisions about the contents of a file based on the file name extension. For example, a file that is named Form1.vb may not be a Visual Basic source file.

The LineInput function reads from a file one character at a time until it encounters a carriage return (Chr(13)) or carriage return/line feed (Chr(13) + Chr(10)) sequence. Carriage return/line feed sequences are skipped instead of appended to the character string.

Security noteSecurity Note

Reading from a file by using the LineInput function requires Read access from the FileIOPermissionAccess enumeration.

This example uses the LineInput function to read a line from a sequential file and assign it to a variable. This example assumes that TestFile is a text file that has several lines of sample data.

Dim TextLine As String 
' Open file.
FileOpen(1, "TESTFILE", OpenMode.Input)
' Loop until end of file. 
While Not EOF(1)
    ' Read line into variable.
    TextLine = LineInput(1)
    ' Print to the console.
    Console.WriteLine("1", TextLine)
End While
FileClose(1)

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft