Use ASP to read and display text files

Source: Internet
Author: User

Read a text file and write sun Aug 2 06:34:07 1998

(Note: textstream write Method

Write (string)

Writeline (string)

Writeblanklines (lines)

)

This is a complete program

<HTML> 〉

<Head> 〉

<Http-equiv = "Content-Type" content = "text/html; charset = gb2312"> "〉

<Title> </title> 〉

</Head> 〉

<Body> 〉

<% Language = VBScript %>

<%

Const forreading = 1, forwriting = 2, forappending = 8

Const tristateusedefault =-2, tristatetrue =-1, tristatefalse = 0

Dim filename

Filename = "test.txt" 'the default relative path is C: winnt

Set FS = Createobject ("scripting. FileSystemObject ")

Set F = FS. GetFile (filename)

Set readf = f. openastextstream (forreading, tristatefalse)

'The first parameter is optional. The input/output mode is one of the following three constants:

'Forreading = 1 read-only, forwriting = 2 read/write or forappending = 3 append

'The second parameter is also optional. One of the three tristate values,

'Indicates the format in which the file is opened. If this parameter is ignored, the file uses ASCII

'Format. Tristateusedefault =-2 open a file in the system default format,

'Tristatetrue =-1 open a file in unicode format or tristatefalse = 0

'Open the file in ASCII format.

'You can also use the opentextfile method to open a file.

S = readf. Readline

Do While readf. atendofline <> true

S = readf. Readline

Response. Write S & "" 'read and write files row by row

Loop

Readf. Close

%>

</Body>

</Html>

In this way, the text file can be read and displayed.

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.