Javascript FSO textstream File WriteBlankLines Method

Updated on 29 Mar 2012,
Published on 17 Oct 2008

Javascript FileSystemObject (FSO) textstream file WriteBlankLines method provides the functionality to write the specified number of blank line into the textstream file. Both CreateTextFile and OpenTextFile methods support WriteBlankLines method of textstream that allows you to insert blank lines into the specified file. WriteBlankLines method of textstream object inserts the specified number of blank lines and a new-line character at the end of each line. 

Syntax for Javascript FSO textsream File WriteBlankLines method

textStreamObj.WriteBlankLines( Lines );

WriteBlankLines method of textstream object accepts one parameter Lines of integer type. This Lines parameter accepts integer value to specify the number of blank lines to be inserted into the textstream file.

Example of FSO textstream File WriteBlankLines 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. ");

    // inserts specified number of blank lines
    txtFile.WriteBlankLines(3);
    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);

    var loop;
    loop = 1;

    while (txtFile.AtEndOfStream != true) {
        fText += loop + ": " + txtFile.ReadLine();
        fText += "<br />";
        loop++;
    }

    document.write(fText);

    // close the open textstream object file
    txtFile.Close();
    fso = null
        
    // Output: 
    // 1: Hello this is the first line of text file. 
    // 2: 
    // 3: 
    // 4: 
    // 5: Hello this is the second line of text file.
</script>

Continue to next tutorial: Javascript FSO textstream File WriteLine Method to learn how to write a text line with new line character in a textstream.

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