源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

VBS教程:方法-OpenAsTextStream 方法

  • 时间:2022-02-05 03:41 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:VBS教程:方法-OpenAsTextStream 方法

OpenAsTextStream 方法

打开指定的文件并返回一个 [b]TextStream[/b] 对象,此对象用于对文件进行读、写或追加操作。 [code][i]object.[/i][b]OpenAsTextStream[/b][i]([iomode, [format]]) [/i][/code] [h3]参数[/h3]object 必选项。应为 [b]File[/b] 对象的名称。 iomode 可选项。输入/输出模式,是下列三个常数之一:ForReading、ForWriting 或 ForAppending。 [i]format[/i] 可选项。三个 [b]Tristate[/b] 值之一,指出以何种格式打开文件。忽略此参数,则文件以 ASCII 格式打开。 [h3]设置[/h3][b]iomode[/b] 参数可为下列设置之一:
常数描述
ForReading1以只读模式打开文件。不能对此文件进行写操作。
ForWriting2以可读写模式打开文件。如果已存在同名的文件,则覆盖旧的文件。
ForAppending8打开文件并在文件末尾进行写操作。
[b]format[/b] 参数可为下列设置之一:
常数描述
TristateUseDefault-2以系统默认格式打开文件。
TristateTrue-1以 Unicode 格式打开文件。
TristateFalse 0以 ASCII 格式打开文件。
[h3]说明[/h3]OpenAsTextStream 方法可提供与 FileSystemObject 对象的 OpenTextFile 方法相同的功能。另外,使用 OpenAsTextStream 方法可对文件进行写操作。 以下代码举例说明如何使用 [b]OpenAsTextStream[/b] 方法:
[code]Function TextStreamTest    Const ForReading = 1, ForWriting = 2, ForAppending = 8    Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0    Dim fso, f, ts    Set fso = CreateObject("Scripting.FileSystemObject")    fso.CreateTextFile "test1.txt"            '[/code]创建一个文件。[code]    Set f = fso.GetFile("test1.txt")[/code][code]    Set ts = [b]f.OpenAsTextStream([/b]ForWriting[b],[/b] TristateUseDefault[b])[/b][/code][code]    ts.Write "[/code]嗨,你好![code]"[/code][code]    ts.Close[/code][code]    Set ts = [b]f.OpenAsTextStream([/b]ForReading[b],[/b] TristateUseDefault[b])[/b][/code][code]  TextStreamTest = ts.ReadLine[/code][code]  ts.Close[/code][code]End Function[/code]
 
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部