Scripting Runtime Library  

Write Method

Writes a specified string to a TextStream file.



Required. Always the name of a TextStream object.
Required. The text you want to write to the file.


Specified strings are written to the file with no intervening spaces or characters between each string. Use the WriteLine method to write a newline character or a string that ends with a newline character.

The following example illustrates the use of the Write method:

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 = fso.OpenTextFile("c:\\testfile.txt", ForReading);
   r = f.ReadLine();
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

See Also

WriteBlankLines Method | WriteLine Method
Applies To: TextStream Object