How to use ASP TextStream objects

Source: Internet
Author: User

In the following example, we will create a new text file Test.txt and write some text. First, we create an instance of the FileSystemObject object and then use the CreateTextFile method to create a new text file. CreateTextFile returns a TextStream object that we will use to write some text files.

<%
Dim objFSO, Objtstream
' Create An instance of the FileSystemObject object
Set objFSO = Server.createo Bject ("Scripting.FileSystemObject")
' Create a text file named MyFile.txt, replacing any existing one with the same Nam E
Set objtstream = objFSO.CreateTextFile ("C:est.txt", True)
' Write some text to the ' file
Objtstream.writeline ("Webcheatsheet ASP tutorials!")
Objtstream.writeblanklines (1)
Objtstream.writeline ("The TextStream Object")
Objtstream.writeblanklines (2)
Objtstream.writeline ("The TextStream object provides sequential access to the contents of text files.")
' Close the TextStream object
Objtstream.close
' free to resources
Set objtstream = Nothing
Set objFSO = Nothing
%>
In the following example, we will carefully read the contents of the Test.txt file. First, we create an instance of the FileSystemObject object and then use the OpenTextFile method to open the Test.txt file for reading. This method returns a TextStream object that we will use to read data from the file. We'll walk through each reading of a row of files.

<%
Dim objFSO, Objtstream
' Create An instance of the FileSystemObject object
Set objFSO = Server.createo Bject ("Scripting.FileSystemObject")
' opens for reading a text file named MyFile.txt
Set objtstream = Objfso.opente Xtfile ("C:est.txt", 1)
' Read one line at a time until the ' the ' the ' the ' the ' the ' the ' of ' the ' the ' of the ' of ' Tream
  Response.Write "line" & Objtstream.line & ":" & Objtstream.readline & "<br/>"
Loop
' close ' TextStream object
Objtstream.close
' free to resources
Set objtstream = Nothing
Set o Bjfso = Nothing
%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.