Javascript File SkipLine Method of textstream object provided by the FileSystemObject (FSO) performs the action of skipping a whole line while reading the textstream. Textstream object’s File SkipLine method skips one line at a time from the specified text file for the OpenTextStream method. After reading a line it moves the cursor position to the starting column of next line and read methods of textstream object continues their reading action from the cursor position reached after the SkipLine method.
Syntax for Javascript FSO textstream File SkipLine method
textStreamObj.SkipLine();
SkipLine method of textstream object does not take any parameter to perform the action as shown in the above syntax.
Example of FSO textstream File SkipLine 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.WriteLine("Hello this is the third 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.ReadLine();
// skips a single line { it will skip the second line coz first line has already been read in the previous code line }
txtFile.SkipLine();
fText += "<br />";
fText += txtFile.ReadLine();
document.write("<b>Text with skipped line:</b><br /> " + fText);
// close the open textstream object file
txtFile.Close();
fso = null
// Output:
// Text with skipped line:
// Hello this is the first line of text file.
// Hello this is the third line of text file.
</script>
Continue to next tutorial: Javascript FSO textstream File Write Method to learn how to write the specified text in a file.