将给定的字符串写入到一个 TextStream 文件。
object.Write(string)
给定的字符串在写入该文件时不会在字符串之间插入空格或字符。可以使用 WriteLine 方法来写入一个换行符或以换行符结束的字符串。
下面的示例演示了Write 方法的用法:
[JScript] function WriteDemo() { var fso, f, r var ForReading = 1, ForWriting = 2; fso = new ActiveXObject("Scripting.FileSystemObject") f = fso.OpenTextFile("c:\\testfile.txt", ForWriting, true)f.Write(
"Hello world!")
; f.Close(); f = fso.OpenTextFile("c:\\testfile.txt", ForReading); r = f.ReadLine(); return(r); } [VBScript] Function WriteToFile Const ForReading = 1, ForWriting = 2 Dim fso, f Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)f.Write
"Hello world!" Set f = fso.OpenTextFile("c:\testfile.txt", ForReading) WriteToFile = f.ReadLine End Function