使用ASP读出文本文件并显示

王朝asp·作者佚名  2006-12-16
窄屏简体版  字體: |||超大  

(注:textStream有关写的METHOD

Write(STRING)

WriteLine(STRING)

WriteBlankLines(LINES)

这是一个完整的程序

〈 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" ’缺省相对路径是c:winnt

Set fs = CreateObject("Scripting.FileSystemObject")

Set f = fs.GetFile(filename)

Set readf = f.OpenAsTextStream(ForReading,TristateFalse)

’第一个参数可选。输入/输出模式,是下列三个常数之一:

’ ForReading=1只读、ForWriting=2 可读写或 ForAppending=3追加

’第二个参数也为可选。三个 Tristate 值之一,

’ 指出以何种格式打开文件。忽略此参数,则文件以 ASCII

’格式打开。 TristateUseDefault=-2 以系统默认格式打开文件、

’TristateTrue=-1 以 Unicode 格式打开文件或TristateFalse=0

’以 ASCII 格式打开文件。

’也可用OpenTextFile方法打开文件

s = readf.ReadLine

Do While readf.AtEndOfLine <> True

s = readf.ReadLine

Response.write s & "" ’逐行读文件并写出

Loop

readf.close

% >

< /body>

< /html>

这样就可以将文本文件读出并显示了。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航