ASP OpenAsTextStream 方法

定义和用法

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

คำสั่ง

FileObject.OpenAsTextStream(mode,format)
ตัวแปร รายละเอียด
mode ตัวเลือกได้. รูปแบบการเปิดแฟ้ม (การอ่าน/เขียน)
  • 1 = ForReading - เปิดแฟ้มด้วยโหมดอ่านเท่านั้น
  • 2 = ForWriting - เปิดแฟ้มด้วยโหมดเขียน/อ่าน
  • 8 = ForAppending - เปิดแฟ้มและเขียนบนสุดของแฟ้ม
format ตัวเลือกได้. รูปแบบการเปิดแฟ้ม
  • 0 = TristateFalse - รูปแบบเริ่มต้น。เปิดแฟ้มด้วยรูปแบบ ASCII
  • -1 = TristateTrue - เปิดแฟ้มด้วย Unicode
  • -2 = TristateUseDefault - ใช้รูปแบบการเปิดแฟ้มเริ่มต้นของระบบ

รายละเอียด

<%
dim fs,f,ts
set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.GetFile("c:\test.txt")
Set ts=f.OpenAsTextStream(ForWriting)
ts.Write("Hello World!")
ts.Close
Set ts=f.OpenAsTextStream(ForReading)
Response.Write(ts.ReadAll)
ts.Close
set ts=nothing
set f=nothing
set fs=nothing
%>

การแสดงผล:

Hello World!