Đối tượng TextStream của ASP
Đối tượng TextStream được sử dụng để truy cập nội dung của tệp văn bản.
Thêm ví dụ
Đọc tập tin văn bản
Cách đọc từ một tập tin văn bản.
Chỉ đọc một phần của tệp văn bản
Cách chỉ đọc một phần của tệp TextStream.
Đọc một dòng của tệp văn bản
Cách đọc một dòng từ tệp TextStream.
Đọc tất cả các dòng từ một tệp văn bản
Cách đọc tất cả các dòng từ tệp TextStream.
Bỏ qua một phần của tệp văn bản
Cách bỏ qua một số ký tự được chỉ định khi đọc tệp TextStream.
Bỏ qua một dòng của tệp văn bản
Cách bỏ qua một dòng khi đọc tệp TextStream.
Trả về số dòng
Cách trả về số dòng hiện tại trong tệp TextStream.
Lấy số cột
Cách lấy số cột của ký tự hiện tại trong một 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 thể hiệ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 thể hiệ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 File.
Các thuộc tính và phương thức của đối tượng TextStream được mô tả bên dưới:
Của cải
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 |