ASP CreateTextFile 方法

CreateTextFile 方法在當前檔夾創建一個新的文本檔,並返回一個供讀寫此檔的 TextStream 對象。
語法
FileSystemObject.CreateTextFile(filename[,overwrite[,unicode]])
FolderObject.CreateTextFile(filename[,overwrite[,unicode]])
FolderObject.CreateTextFile(filename[,overwrite[,unicode]])
參數 | 描述 |
---|---|
filename | 必需的。要創建的檔的名稱。 |
overwrite | 可選的。指示是否可覆蓋已有檔的布爾值。True 表示可覆蓋此檔,False 表示不可覆蓋此檔。默認是 True。 |
unicode | 可選的。指示以 Unicode 格式還是 ASCII 格式創建檔。True 指示以 Unicode 格式創建檔,False 指示以 ASCII 格式創建檔。默認是 False。 |
針對 File 對象的實例
<%
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
%>
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
%>
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
%>
