ASP CreateTextFile 方法

定義和用法

CreateTextFile 方法可在當前文件夾中創建新的文本文件,并返回可用于讀或寫文件的 TextStream 對象。

語法:

FileSystemObject.CreateTextFile(filename[,overwrite[,unicode]])
FolderObject.CreateTextFile(filename[,overwrite[,unicode]])
參數 描述
filename 必需的。需創建文件的名稱。
overwrite 可選的。指示能否覆蓋已有文件的布爾值。True 指示可覆蓋文件,False 指示不能覆蓋文件。默認是 True 。
unicode 可選的。指示文件是作為 Unicode 還是 ASCII 文件來創建的布爾值。True 指示文件作為 Unicode 文件創建,而 False 指示文件被作為 ASCII 文件創建。默認是 False。

針對 FileSystemObject 對象的實例

<%
dim fs,tfile
set fs=Server.CreateObject("Scripting.FileSystemObject")
set tfile=fs.CreateTextFile("c:\somefile.txt")
tfile.WriteLine("Hello World!")
tfile.close
set tfile=nothing
set fs=nothing
%>

針對 Folder 對象的實例

<%
dim fs,fo,tfile
Set fs=Server.CreateObject("Scripting.FileSystemObject") 
Set fo=fs.GetFolder("c:\test") 
Set tfile=fo.CreateTextFile("test.txt",false) 
tfile.WriteLine("Hello World!")
tfile.Close
set tfile=nothing
set fo=nothing
set fs=nothing
%>