October 31, 2000 - File I/O
![]() |
October 31, 2000 File I/O Tips: October 2000
Yehuda Shiran, Ph.D.
|
OpenAsTextStream() method of the File object. Its syntax is as follows:
file.OpenAsTextStream(iomode, format);
where iomode can get the following values:
Constant Value Description ForReading1 Open a file for reading only. You can't write to this file. ForWriting2 Open a file for writing. ForAppending8 Open a file and write to the end of the file.
And format can be set to three values:
Constant Value Description TristateUseDefault-2 Open the file using the system default TristateTrue-1 Open the file as Unicode TristateFalse0 Open the file in ASCII mode
Here is a code that creates a new file, opens it for writing in ASCII mode, and writes "Hello World" to it. At the end, it closes the file:
<SCRIPT LANGUAGE="JavaScript">
<!--
var TristateFalse = 0;
var ForWriting = 2;
myActiveXObject = new ActiveXObject("Scripting.FileSystemObject");
myActiveXObject.CreateTextFile("c:\\test.txt");
file = myActiveXObject.GetFile("c:\\test.txt");
text = file.OpenAsTextStream(ForWriting, TristateFalse);
text.Write("Hello World");
text.Close();
// -->
</SCRIPT>Notice that you have to define the constants by yourself.



