手机
当前位置:查字典教程网 >编程开发 >ASP教程 >怎样读取一个文本文件的内容?
怎样读取一个文本文件的内容?
摘要:EverwanttoknowhowtodisplaythecontentsofatextdocumentusingASP.Hereisaea...

Ever want to know how to display the contents of a text document using ASP. Here is a easy way to read

from a text file

<-->

<%

'by James Seymour, http://jamesdot.org

Dim write

Dim fileSysObj, tf, read

' Read the read.txt

' Store the file name where the Information is stored into a variable called read

read = "read.txt"

' Retrieve the fullpath of the read file

read = LEFT(Server.Mappath(Request.ServerVariables("PATH_INFO")), InStrRev(Server.Mappath

(Request.ServerVariables("PATH_INFO")), "")) & read

' Create an instance of FileSystem Object and store it into a variable called fileSysObj

Set fileSysObj = createObject("Scripting.FileSystemObject")

' Check whether the read file exists

IF (fileSysObj.FileExists(read)) Then

' if the file exists, then open it for reading

Set tf = filesysobj.OpenTextFile(read, 1)

read = tf.ReadLine

tf.Close

ELSE

' if you can't find read.text, display default message

read = "I can't find the file read.txt! So this is my default message."

END IF

%>

' table the displays the read.txt file

<div align="center">

<center>

<table border="0" width="40%" cellspacing="0" cellpadding="0">

<tr>

<td width="100%" bgcolor="#EEEECC"><B><%=read%></B>

</td>

</tr>

<tr>

<td width="100%">

<>

use the code above, click and drag your mouse over the code to highlight it. Then right click on the

highlighted code and click "Copy." Now you may paste it into your code editor.

【怎样读取一个文本文件的内容?】相关文章:

读取目录下的所有文件(包括子目录下的所有文件)

asp实现获取MSSQL数据库表指定条件行数的函数

读取目录下的文件得到一个数组

FSO 读出TXT文件

计算两个时间之差的函数

一个防止被采集的方法

asp限制上传文件大小实例

用ASP打开远端MDB文件的方法

整理了一个editplus的剪辑文件(ASP方面的内容)

图片的入库与读取的方法

精品推荐
分类导航