LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

asp OpenTextFile文本读取与写入实例代码

admin
2011年12月22日 11:8 本文热度 2347
打开指定的文件并返回一个 TextStream 对象,可以读取、写入此对象或将其追加到文件。
object.OpenTextFile(filename[, iomode[, create[, format]]])
参数
object :必选项。应为 FileSystemObject 对象的名称。
filename :必选项。字符串表达式,指明要打开的文件名称。
iomode :可选项。输入/输出模式,是下列三个常数之一:ForReading,ForWriting,或 ForAppending。
create :可选项。Boolean 值,指出当指定的 filename 不存在时是否能够创建新文件。允许创建新文件时为 True,否则为 False。默认值为 False。
format :可选项。三个 Tristate 值之一,指出以何种格式打开文件。若忽略此参数,则文件以 ASCII 格式打开。
设置
iomode 参数可为下列设置之一:
常数 值 描述
ForReading 1 以只读模式打开文件。不能对此文件进行写操作。
ForWriting 2 以只写方式打开文件。不能对此文件进行读操作。
ForAppending 8 打开文件并在文件末尾进行写操作。
format 参数可为下列设置之一:
常数 值 描述
TristateUseDefault -2 以系统默认格式打开文件。
TristateTrue -1 以 Unicode 格式打开文件。
TristateFalse 0 以 ASCII 格式打开文件。
说明
以下代码举例说明如何使用 OpenTextFile 方法打开写文件:
代码如下:
Sub OpenTextFileTest
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)
f.Write "嗨,你好!"
f.Close
End Sub
 
 

The OpenTextFile method opens a specified file and returns a TextStream object that can be used to access the file.
ASP OpenTextFile的作用是打开一个指定的文件或者返回一个能够访问文件的文本流(TextStream)对象。

Syntax
语法

FileSystemObject.OpenTextFile(fname,mode,create,format)

Parameter参数 Description描述
fname Required. The name of the file to open
必要参数。指定需要打开文件的名称
mode Optional. How to open the file
可选组件。规定打开文件的方式

1=ForReading - Open a file for reading. You cannot write to this file.
1=ForReading(以阅读内容为目的) – 打开文件进行内容阅读,但是你不可以在这个文件上书写内容。
2=ForWriting - Open a file for writing.
2=ForWriting(以书写内容为目的)- 打开文件进行内容书写。
8=ForAppending - Open a file and write to the end of the file.
8=ForAppending(以追加内容为目的)- 打开一个文件直接在这个文件内容最后追加内容

create Optional. Sets whether a new file can be created if the filename does not exist. True indicates that a new file can be created, and False indicates that a new file will not be created. False is default
可选组件。设置是否可以建立一个原本不存在的新文件。如果为true真,则可以建立一个新的文件,如果为false假,则不可以建立一个新的文件。默认情况是false假。
format Optional. The format of the file
可选组件。规定文件的格式

0=TristateFalse - Open the file as ASCII. This is default.
0= TristateFalse – 以ASCII形式打开文件。这是原来的默认属性
-1=TristateTrue - Open the file as Unicode.
-1=TristateTrue – 以Unicode形式打开文件
-2=TristateUseDefault - Open the file using the system default.
-2=TristateUseDefault – 使用系统默认的格式打开文件

Example
举例

<%
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
%> 

该文章在 2011/12/22 11:09:23 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2024 ClickSun All Rights Reserved