JavaScript Tutorial/MS JScript/TextStream

Материал из Web эксперт
Версия от 18:52, 25 мая 2010; (обсуждение)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

TextStream

The TextStream object is created by calling the CreateTextFile() method of the FileSystemObject object.

Methods and Properties of the TextStream Object

Method/Property Description Close() Closes the file Read() Reads in a specified number of characters ReadAll() Reads the entire file ReadLine() Reads a line of the file up to the newline character Skip() Skips the specified number of characters SkipLine() Skips the next line when reading the file Write() Writes a string to the file WriteBlankLines() Writes the specified number of blank lines to the file WriteLine() Writes a string followed by a newline character to the file AtEndOfLine Returns true if the pointer is immediately before the end-of-line marker AtEndOfStream Returns true if the pointer is at the end of the file Column Returns the column number of the current pointer position Line Returns the line number of the current pointer position



<html>
    <script language="JScript">
    <!--
    var myFileSysObj = new ActiveXObject("Scripting.FileSystemObject")
    var myTextStream = myFileSysObj.OpenTextFile("c:\\temp\\test.txt", 2, true)
    myTextStream.Write("Hello, World!");
    myTextStream.Close();
    -->
    </script>
</html>


TextStream.AtEndOfLine

The AtEndOfLine property returns true when the end of a line in a text line is found.



<html>
    <script language="JScript">
    <!--
    var myFileSysObj = new ActiveXObject("Scripting.FileSystemObject");
    var myInputTextStream = myFileSysObj.OpenTextFile("c:\\temp\\test.txt", 1, true);
    var myOutputTextStream = myFileSysObj.OpenTextFile("c:\\temp\\test2.txt", 2, true);
    while(!myInputTextStream.AtEndOfLine){
      myOutputTextStream.Write(myInputTextStream.Read(1));
    }
    myInputTextStream.Close();
    myOutputTextStream.Close();
    -->
    </script>
</html>


TextStream.AtEndOfStream

The AtEndOfStream property returns true when the end of a line in a text file is found.



<html>
    <script language="JScript">
    <!--
    var myFileSysObj = new ActiveXObject("Scripting.FileSystemObject");
    var myInputTextStream = myFileSysObj.OpenTextFile("c:\\temp\\test.txt", 1, true);
    var myOutputTextStream = myFileSysObj.OpenTextFile("c:\\temp\\test2.txt", 2, true);
    while(!myInputTextStream.AtEndOfStream){
      myOutputTextStream.Write(myInputTextStream.Read(1));
    }
    myInputTextStream.Close();
    myOutputTextStream.Close();
    -->
    </script>
</html>


TextStream.Close()

The Close() method closes the previously opened file.



<html>
    <script language="JScript">
    <!--
    var myFileSysObj = new ActiveXObject("Scripting.FileSystemObject");
    var myTextStream = myFileSysObj.OpenTextFile("c:\\temp\\test.txt", 1, true);
    myTextStream.Close();
    -->
    </script>
</html>


TextStream.Column

The Column property returns the column number of the current pointer position.



<html>
    <script language="JScript">
    <!--
    var myFileSysObj = new ActiveXObject("Scripting.FileSystemObject");
    var myInputTextStream = myFileSysObj.OpenTextFile("c:\\temp\\test.txt", 1, true);
    var myOutputTextStream = myFileSysObj.OpenTextFile("c:\\temp\\test2.txt", 2, true);
    while(!myInputTextStream.AtEndOfStream){
      myOutputTextStream.Write(myInputTextStream.Column + ": ");
      myOutputTextStream.WriteLine(myInputTextStream.Read(1));
    }
    myInputTextStream.Close();
    myOutputTextStream.Close();
    -->
    </script>
</html>


TextStream.Line

The Line property returns the line number of the current pointer position.



<html>
    <script language="JScript">
    <!--
    var myFileSysObj = new ActiveXObject("Scripting.FileSystemObject");
    var myInputTextStream = myFileSysObj.OpenTextFile("c:\\temp\\test.txt", 1, true);
    var myOutputTextStream = myFileSysObj.OpenTextFile("c:\\temp\\test2.txt", 2, true);

    while(!myInputTextStream.AtEndOfStream){
      myOutputTextStream.Write(myInputTextStream.Line + ": ");
      myOutputTextStream.WriteLine(myInputTextStream.Read(1));
    }
    myInputTextStream.Close();
    myOutputTextStream.Close();
    -->
    </script>
</html>


TextStream.Read()

Syntax



textstream.Read(num)


TextStream.ReadAll()

The ReadAll() method reads the entire text file.



<html>
    <script language="JScript">
    <!--
    var myFileSysObj = new ActiveXObject("Scripting.FileSystemObject");
    var myInputTextStream = myFileSysObj.OpenTextFile("c:\\temp\\test.txt", 1, true);
    var myOutputTextStream = myFileSysObj.OpenTextFile("c:\\temp\\test2.txt", 2, true);
    while(!myInputTextStream.AtEndOfStream){
      myOutputTextStream.Write(myInputTextStream.ReadAll());
    }
    myInputTextStream.Close();
    myOutputTextStream.Close();
    -->
    </script>
</html>


TextStream.ReadLine()

The ReadLine() method reads a line from a text file up to a newline character.



<html>
    <script language="JScript">
    <!--
    var myFileSysObj = new ActiveXObject("Scripting.FileSystemObject");
    var myInputTextStream = myFileSysObj.OpenTextFile("c:\\temp\\test.txt", 1, true);
    var myOutputTextStream = myFileSysObj.OpenTextFile("c:\\temp\\test2.txt", 2, true);
    while(!myInputTextStream.AtEndOfStream){
      myOutputTextStream.WriteLine(myInputTextStream.ReadLine());
    }
    myInputTextStream.Close();
    myOutputTextStream.Close();
    -->
    </script>
</html>


TextStream.Skip()

Syntax



textstream.Skip(num)


TextStream.SkipLine()

The SkipLine() skips the next line.



<html>
    <script language="JScript">
    <!--
    var myFileSysObj = new ActiveXObject("Scripting.FileSystemObject");
    var myInputTextStream = myFileSysObj.OpenTextFile("c:\\temp\\test.txt", 1, true);
    var myOutputTextStream = myFileSysObj.OpenTextFile("c:\\temp\\test2.txt", 2, true);
    myInputTextStream.SkipLine();
    while(!myInputTextStream.AtEndOfStream){
      myOutputTextStream.Write(myInputTextStream.Read(1));
    }
    myInputTextStream.Close();
    myOutputTextStream.Close();
    -->
    </script>
</html>


TextStream.Write()

Syntax



textstream.Write(string)


TextStream.WriteBlankLines()

Syntax



textstream.WriteBlankLines(num)


TextStream.WriteLine()

The WriteLine() method writes a string followed by a newline to the text file.



<html>
    <script language="JScript">
    <!--
    var myFileSysObj = new ActiveXObject("Scripting.FileSystemObject")
    var myTextStream = myFileSysObj.OpenTextFile("c:\\temp\\test.txt", 2, true)
    myTextStream.WriteLine("Hello, World!");
    myTextStream.Close();
    -->
    </script>
</html>