FileClose 函数

更新:2007 年 11 月

关闭对用 FileOpen 函数打开的文件的输入/输出 (I/O)。

在文件 I/O 操作中,My 具有更高的效率和更好的性能。有关更多信息,请参见 My.Computer.FileSystem 对象

Public Sub FileClose(ParamArray FileNumbers() As Integer)

参数

  • FileNumbers
    可选。要关闭的 0 个或多个信道的参数数组。

异常

异常类型

错误号

条件

IOException

52

FileNumber 不存在。

如果正在升级使用无结构错误处理的 Visual Basic 6.0 应用程序,请参见“错误号”一列。(您可以根据 Number 属性(Err 对象)比较错误号。)然而,如果可能,应当考虑用 Visual Basic 的结构化异常处理概述替换这种错误控制。

备注

提供 FileClose 函数是为了实现后向兼容性,可能会影响性能。对于非旧式应用程序,My.Computer.FileSystem 对象将提供更好的性能。有关更多信息,请参见使用 Visual Basic 访问文件

如果省略 FileNumbers,则将关闭由 FileOpen 函数打开的所有活动文件。

当关闭以 Output 或 Append 模式打开的文件时,最终输出缓冲区将写入此文件的操作系统缓冲区。所有与已关闭的文件关联的缓冲区空间都被释放。

当执行 FileClose 函数时,文件与其文件号之间的关联将终结。

示例

本示例使用 FileClose 函数关闭以 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.

智能设备开发人员说明

不支持此函数。

要求

命名空间:Microsoft.VisualBasic

**模块:**FileSystem

**程序集:**Visual Basic 运行库(在 Microsoft.VisualBasic.dll 中)

请参见

参考

End 语句

FileOpen 函数

Reset 函数

Stop 语句 (Visual Basic)

其他资源

使用 Visual Basic 访问文件