Javascript FileSystemObject (FSO) textstream object file WriteLine method provides the functionality to write a text string into the specified file. Both CreateTextFile and OpenTextFile methods support WriteLine method of textstream that allows you to write the new string each time this method is called. WriteLine method of textstream object inserts a new-line character between the strings generated by consecutive calls of WriteLine method. 

Syntax for Javascript FSO textstream File WriteLine method

textStreamObj.WriteLine( Text );

WriteLine 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 WriteLine 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.WriteLine("Hello this is the first line of text file. ");
    txtFile.WriteLine("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("<pre>" + fText + "</pre>");

    // 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 FileSystemObject Drive AvailableSpace property to learn how to get the available space on specified drive.

Recent JavaScript Tutorials

Javascript FSO ShortPath property

Javascript FileSystemObject (FSO) provides a ShortPath property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Path Property

Javascript FileSystemObject (FSO) provides the Path property that can be accessed through the file object or folder object returned by the GetFile or GelFolder method

Javascript FSO Type property

Javascript FileSystemObject (FSO) provides a Type property that can be accessed through file object or folder object returned by the GetFile or GetFolder method

Javascript FSO ShortName property

Javascript FileSystemObject (FSO) provides a ShortName property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Name Property

Javascript FileSystemObject (FSO) provides a Name property that can be accessed using file object or folder object.