Đối tượng dòng văn bản ASP


Đối tượng TextStream được sử dụng để truy cập nội dung của tệp văn bản.


Các ví dụ khác


tệp văn bản Cách đọc từ tệp văn bản.


Cách chỉ đọc một phần của tệp TextStream.


tệp văn bản Cách đọc một dòng từ tệp TextStream.


từ tệp văn bản Cách đọc tất cả các dòng từ tệp TextStream.


tệp văn bản Cách bỏ qua một số ký tự được chỉ định khi đọc tệp TextStream.


tệp văn bản Cách bỏ qua một dòng khi đọc tệp TextStream.


Cách trả về số dòng hiện tại trong tệp TextStream.


Cách lấy số cột của ký tự hiện tại trong tệp.


Đối tượng TextStream

Đối tượng TextStream được sử dụng để truy cập nội dung của tệp văn bản.

Đoạn mã sau tạo một tệp văn bản (c: \ test.txt) và sau đó ghi một số văn bản vào tệp (biến f là một phiên bản của đối tượng 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
%>


Để tạo một phiên bản của đối tượng TextStream, bạn có thể sử dụng các phương thức CreateTextFile hoặc OpenTextFile của đối tượng FileSystemObject hoặc bạn có thể sử dụng phương thức OpenAsTextStream của đối tượng Tệp.

Các thuộc tính và phương thức của đối tượng TextStream được mô tả bên dưới:

Tính chất

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

Phương pháp

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