spacer
Yehuda Shiran October 31, 2000
File I/O
Tips: October 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management
You can use JavaScript to do real stuff on your computer. Among other things, you can open a file, read from a file, and write to a file. You do it by the OpenAsTextStream() method of the File object. Its syntax is as follows:

file.OpenAsTextStream(iomode, format);

where iomode can get the following values:

ConstantValueDescription
ForReading1Open a file for reading only. You can't write to this file.
ForWriting2Open a file for writing.
ForAppending8Open a file and write to the end of the file.

And format can be set to three values:

ConstantValueDescription
TristateUseDefault-2Open the file using the system default
TristateTrue-1Open the file as Unicode
TristateFalse0Open 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.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags