ActiveXObject对象的OpenTextFile方法介绍

本文介绍了如何使用OpenTextFile方法打开文本文件,并通过TextStream对象进行读写操作。详细解释了方法的参数含义及用法,并提供了一个具体的示例代码。此外,还列举了多个与文件操作相关的属性和方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

OpenTextFile方法打开一个指定的文件并返回一个TextStream对象以用来访问这个文件。

一、语法
FileSystemObject.OpenTextFile(fname,mode,create,format)
参数说明:
fname:必须的。要打开的文件的名字。
mode:可选的。以什么方式打开。1=ForReading(以只读方式打开),2=ForWriting (以写方式打开),8=ForAppending(以添加方式打开,写入的内容将添加到文件末尾)。
create:可选的。设置如果所打开的文件不存在是否创建该文件。True为是,False为否。默认是False。
format:可选的。文件的格式。0=TristateFalse(以ASCII格式打开,这是默认的),-1=TristateTrue(以Unicode格式打开),-2=TristateUseDefault (以系统默认方式打开)

二、例子
<%
dim fs,f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.OpenTextFile(Server.MapPath("testread.txt"),8,true)
f.WriteLine("This text will be added to the end of file")
f.Close
set f=Nothing
set fs=Nothing
%>  

Property
属性 Description
描述
Attributes
Sets or returns the attributes of a specified file
设置或返回指定文件的属性
DateCreated
Returns the date and time when a specified file was created
返回指定文件建立的日期和时间
DateLastAccessed
Returns the date and time when a specified file was last accessed
返回指定文件最后被访问的日期和时间
DateLastModified
Returns the date and time when a specified file was last modified
返回指定文件最后被修改的日期和时间
Drive
Returns the drive letter of the drive where a specified file or folder resides
返回指定文件或文件夹所处的盘符的盘符号
Name
Sets or returns the name of a specified file
设置或返回指定文件的名字
ParentFolder
Returns the folder object for the parent of the specified file
返回指定文件的父文件夹
Path
Returns the path for a specified file
返回一个指定文件的路径
ShortName
Returns the short name of a specified file (the 8.3 naming convention)
返回一个指定文件的短名 (根据8.3 命名规则)
ShortPath
Returns the short path of a specified file (the 8.3 naming convention)
返回一个指定文件的短路径 (根据8.3 命名规则)
Size
Returns the size, in bytes, of a specified file
返回指定文件所包含的字节数
Type
Returns the type of a specified file
返回指定文件的类型

Methods
方法
Method
方法 Description
描述
Copy
Copies a specified file from one location to another
将本机上的文件复制到异地机子上
Delete Deletes a specified file
删除指定文件
Move
Moves a specified file from one location to another
将本机上的文件移动到异地机子上
OpenAsTextStream
Opens a specified file and returns a TextStream object to access the file
打开指定文件返回一个TextStream对象
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值