Obiekt strumienia tekstu ASP
Obiekt TextStream służy do uzyskiwania dostępu do zawartości pliku tekstowego.
Więcej przykładów
Jak czytać z pliku tekstowego.
Jak odczytać tylko część pliku TextStream.
Jak odczytać jedną linię z pliku TextStream.
Jak odczytać wszystkie wiersze z pliku TextStream.
Jak pominąć określoną liczbę znaków podczas odczytu pliku TextStream.
Jak pominąć linię podczas czytania pliku TextStream.
Jak zwrócić bieżący numer wiersza w pliku TextStream.
Jak uzyskać numer kolumny bieżącego znaku w pliku.
Obiekt TextStream
Obiekt TextStream służy do uzyskiwania dostępu do zawartości plików tekstowych.
Poniższy kod tworzy plik tekstowy (c:\test.txt), a następnie zapisuje w nim jakiś tekst (zmienna f jest instancją obiektu TextStream):
<%
dim fs,f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.CreateTextFile("c:\test.txt",true)
f.WriteLine("Hello World!")
f.Close
set f=nothing
set fs=nothing
%>
Aby utworzyć instancję obiektu TextStream, można użyć metod CreateTextFile lub OpenTextFile obiektu FileSystemObject albo metody OpenAsTextStream obiektu File.
Poniżej opisano właściwości i metody obiektu TextStream:
Nieruchomości
Property | Description |
---|---|
AtEndOfLine | Returns true if the file pointer is positioned immediately before the end-of-line marker in a TextStream file, and false if not |
AtEndOfStream | Returns true if the file pointer is at the end of a TextStream file, and false if not |
Column | Returns the column number of the current character position in an input stream |
Line | Returns the current line number in a TextStream file |
Metody
Method | Description |
---|---|
Close | Closes an open TextStream file |
Read | Reads a specified number of characters from a TextStream file and returns the result |
ReadAll | Reads an entire TextStream file and returns the result |
ReadLine | Reads one line from a TextStream file and returns the result |
Skip | Skips a specified number of characters when reading a TextStream file |
SkipLine | Skips the next line when reading a TextStream file |
Write | Writes a specified text to a TextStream file |
WriteLine | Writes a specified text and a new-line character to a TextStream file |
WriteBlankLines | Writes a specified number of new-line character to a TextStream file |