ASP Getting Started Tutorial-Creating a text file

Source: Internet
Author: User

First, the steps to create a text file are as follows:

1, create FileSystemObject object instance;

    <% Set fso=Server.CreateObject("Scripting.FileSystemObject") %>

2, create TextStream object instance;

    <% txtFile=fso.CreateTextFile(filename[,overwrite[,unicode]]) %>

3, use the method of TextStream object to write to the file.

After you use the CreateTextFile method to create a text file, you can write to the file by using the method of the TextStream object, mainly in the following ways:

1 Write a string to the TextStream file using the Write method, with the following syntax:

txtFile.Write(string)

Where txtfile is a required parameter and should be the name of the Textsteam file object. String is an optional parameter that specifies the text to be written to the file.

2 write the specified string and new line characters to the TextStream file using the WriteLine method, in the following syntax format:

txtFile.WriteLine(string)

Where txtfile is a required parameter and should be the name of the Textsteam file object. String is an optional parameter that specifies the text to be written to the file. If omitted, new line characters are written to the file.

3 Use the WriteBlankLines method to write a specified number of new line characters in the TextStream file in the following syntax format:

txtFile.WriteBlankLines(lines)

Where txtfile is a required parameter and should be the name of the Textsteam file object. Lines is also a required parameter, specifying the number of new line characters to write to the file.

4 Closes the open TextStream file using the Close method, with the following syntax:

txtFile.Close

Ii. properties and methods of the TextStream object:

1. Properties of the TextStream object

Properties of the TextStream object
Property Description
AtEndOfLine Returns True if the file pointer is at the end of a row in the file, or False.
AtEndOfStream Returns True if the file pointer is at the end of the file, or False.
Column Returns the first column of the file's current row in the file pointer.
Line Returns the file pointer at the first row of the file's current row.
         

2, the method of TextStream object

Methods of TextStream Objects < table two >

Method Description
Close Closes the file.
Read (Num) Reads the following num characters from the position of the file pointer and then stores them to the string.
ReadAll Reads the entire file and then holds it to the string.
ReadLine Reads a row from the position of the file pointer and then holds it to the string.
Skip (Num) The Num characters are skipped when the file is read.
SkipLine Read a file skip a row.
Write (strion) Writes strings string to a file.
WriteLine (sring) Writes string strings to a file with a newline character (vbCrLf) followed by a string that is written to a blank line if no string is specified.
WriteBlankLines (Num) Writes Num newline character (vbCrLf) to a file, which writes Num blank lines.

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.