ASP OpenTextFile Method

Definition and Usage

The OpenTextFile method opens the specified file and returns a TextStream object that can be used to access this file.

Syntax:

FileSystemObject.OpenTextFile(fname,mode,create,format)
Parameter Description
fname Required. The name of the file to be opened.
mode Optional. How to open the file.
  • 1=ForReading - Open file for reading data. You cannot write data to this file.
  • 2=ForWriting - Open file for writing data.
  • 8=ForAppending - Open file and write data to the end of the file.
create Optional. Set whether to create a new file if the filename does not exist. True indicates that a new file can be created, while False indicates that a new file will not be created. False is the default.
format Optional. File format.
  • 0=TristateFalse - Open file in ASCII. Default.
  • -1=TristateTrue - Open file in Unicode.
  • -2=TristateUseDefault - Open file using the system default format.

instance

<%
dim fs,f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.OpenTextFile(Server.MapPath("testread.txt"),8,true)
f.WriteLine("Этот текст будет добавлен в конец файла")
f.Close
set f=Nothing
set fs=Nothing
%>