Objek TextStream ASP


Objek TextStream digunakan untuk mengakses konten file teks.


Lebih Banyak Contoh


file teks Cara membaca dari file teks.


Bagaimana membaca hanya sebagian dari file TextStream.


Cara membaca satu baris dari file TextStream.


Cara membaca semua baris dari file TextStream.


Cara melewati sejumlah karakter tertentu saat membaca file TextStream.


Cara melewati satu baris saat membaca file TextStream.


Cara mengembalikan nomor baris saat ini dalam file TextStream.


Cara mendapatkan nomor kolom karakter saat ini dalam file.


Objek TextStream

Objek TextStream digunakan untuk mengakses konten file teks.

Kode berikut membuat file teks (c:\test.txt) dan kemudian menulis beberapa teks ke file (variabel f ​​adalah turunan dari objek 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
%>


Untuk membuat instance objek TextStream, Anda dapat menggunakan metode CreateTextFile atau OpenTextFile dari objek FileSystemObject, atau Anda dapat menggunakan metode OpenAsTextStream dari objek File.

Properti dan metode objek TextStream dijelaskan di bawah ini:

Properti

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

Metode

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