Export (0) Print
Expand All

FileSystem.FileClose Method

Concludes input/output (I/O) to a file opened using the FileOpen function. My gives you better productivity and performance in file I/O operations. See FileSystem for more information.

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

public static void FileClose(
	params int[] FileNumbers
)

Parameters

FileNumbers
Type: System.Int32[]

Optional. Parameter array of 0 or more channels to be closed.

ExceptionCondition
IOException

FileNumber does not exist.

The FileClose 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 How to: Read Text from Files with a StreamReader (Visual Basic), How to: Write Text to Files with a StreamWriter in Visual Basic, and Walkthrough: Manipulating Files and Directories in Visual Basic.

If you omit FileNumbers, all active files opened by the FileOpen function are closed.

When you close files that were opened for Output or Append, the final buffer of output is written to the operating system buffer for that file. All buffer space associated with the closed file is released.

When the FileClose function is executed, the association of a file with its file number ends.

This example uses the FileClose function to close a file opened for Input.

Dim TextLine As String
FileOpen(1, "TESTFILE", OpenMode.Input)   ' Open file.
Do While Not EOF(1)   ' Loop until end of file.
    TextLine = LineInput(1)   ' Read line into variable.
    MsgBox(TextLine)   ' Display the line
Loop
FileClose(1)   ' Close file.

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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.

Show:
© 2014 Microsoft