Objekt ASP TextStream
Objekt TextStream se používá pro přístup k obsahu textového souboru.
Další příklady
Jak číst z textového souboru.
Jak číst pouze část souboru TextStream.
Jak číst jeden řádek ze souboru TextStream.
Jak číst všechny řádky ze souboru TextStream.
Jak přeskočit zadaný počet znaků při čtení souboru TextStream.
Jak přeskočit řádek při čtení souboru TextStream.
Jak vrátit aktuální číslo řádku v souboru TextStream.
Jak získat číslo sloupce aktuálního znaku v souboru.
Objekt TextStream
Objekt TextStream se používá pro přístup k obsahu textových souborů.
Následující kód vytvoří textový soubor (c:\test.txt) a poté do něj zapíše nějaký text (proměnná f je instancí objektu 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
%>
Chcete-li vytvořit instanci objektu TextStream, můžete použít metody CreateTextFile nebo OpenTextFile objektu FileSystemObject nebo můžete použít metodu OpenAsTextStream objektu File.
Vlastnosti a metody objektu TextStream jsou popsány níže:
Vlastnosti
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 |