ÄúµÄλÖãºÑ°ÃÎÍøÊ×Ò³£¾±à³ÌÀÖÔ°£¾VBScript£¾VBScript


objects constants operators statements functions properties methods







METHOD:  File.OpenAsTextStream

object.OpenAsTextStream([iomode [, format]])

This method opens a specified file and returns an instance of a TextStream object that can then be manipulated - read from, written or appended to.

This method has two optional parameters. The first, iomode, has the following available values:

Constant Value   Description
ForReading
1
File is opened for reading only
ForWriting
2
File is opened for writing and the contents of any existing file with the same name are overwritten
ForAppending
8
Opens the file and writes to the end of any existing text.


The second optional parameter, format, can have any of the following values:

Constant Value   Description
TriStateUseDefault
-2
Uses the system default file format
TriStateTrue
-1
Opens the file using the Unicode format
TriStateFalse
0
Opens the file in AscII format


Code:
<%
dim filesys, demofile, txtstream
set filesys = CreateObject ("Scripting.FileSystemObject")
set demofile = filesys.CreateTextFile ("c:\somefile.txt", true)
set demofile = filesys.GetFile("c:\somefile.txt")
set txtstream = demofile.OpenAsTextStream (2, -2)
txtstream.Write "This will overwrite any text already in the file."
txtstream.Close

%>