Javascript FSO textstream File Write Method

Updated on 29 Mar 2012,
Published on 17 Oct 2008

Javascript FileSystemObject (FSO), textstream object’s file Write method provides the functionality to write a given text string or characters into the specified file. Both CreateTextFile and OpenTextFile methods support write method of textstream that allows you to write the continuous long string into the specified file. Write method of textstream object does not insert any space or new-line character between the strings generated by consecutive calls of write method. 

Syntax for Javascript FSO textstream File Write Method

textStreamObj.Write( Text );

Write method of FSO textstream object accepts one parameter Text as shown in the above syntax. This text parameter accepts a string value that is to be written into the specified file.

Example of FSO textstream File Write Method

<script type="text/javascript">
    // initialize ActiveXObject and create an object of Scripting.FileSystemObject.
    var fso = new ActiveXObject("Scripting.FileSystemObject");

    // Open the text file at the specified location with write mode
    var txtFile = fso.OpenTextFile("C:\\Temp\\myFolder\\file.txt", 2, false, 0);
    txtFile.Write("Hello this is the first line of text file. ");
    txtFile.Write("Hello this is the second line of text file. ");

    txtFile.Close();

    var fText;

    // Open the text file at the specified location with read mode
    txtFile = fso.OpenTextFile("C:\\Temp\\myFolder\\file.txt", 1, false, 0);
    fText = txtFile.ReadAll();
    document.write(fText);

    // close the open textstream object file
    txtFile.Close();
    fso = null

    // Output: 
    // Hello this is the first line of text file. Hello this is the second line of text file.
</script>

Continue to next tutorial: Javascript FSO textstream File WriteBlankLines Method to add the specified number of blank lines in the textstream.

0 Responses to "Javascript FSO textstream File Write Method"
Leave a Comment
* required
* required
* will not be published
* optional
* hint: http://www.example.com
  • Subscribe via Email
  • HIRE EzineASP.Net Developers