ASP OpenAsTextStream 方法

定义和用法

OpenAsTextStream 方法打开指定的文件,并返回一个供访问此文件的 TextStream 对象。

语法:
  1. FileObject.OpenAsTextStream(mode,format)
参数描述
mode可选的。如何打开文件(输入/输出模式)。
  • 1 = ForReading - 以只读模式打开文件。不能对此文件进行写操作。
  • 2 = ForWriting - 以可读写模式打开文件。如果已存在同名的文件,则覆盖旧的文件。
  • 8 = ForAppending - 打开文件并在文件末尾进行写操作。
format可选的。以何种格式打开文件。忽略此参数,则文件以 ASCII 格式打开。
  • 0 = TristateFalse - 默认。以 ASCII 格式打开文件。
  • -1 = TristateTrue - 以 Unicode 文件打开文件。
  • -2 = TristateUseDefault - 使用系统默认格式打开文件。

实例

  1. <%
  2. dim fs,f,ts
  3. set fs=Server.CreateObject("Scripting.FileSystemObject")
  4. Set f=fs.GetFile("c:\test.txt")
  5. Set ts=f.OpenAsTextStream(ForWriting)
  6. ts.Write("Hello World!")
  7. ts.Close
  8. Set ts=f.OpenAsTextStream(ForReading)
  9. Response.Write(ts.ReadAll)
  10. ts.Close
  11. set ts=nothing
  12. set f=nothing
  13. set fs=nothing
  14. %>

输出:

  1. Hello World!

分类导航