怎样用asp读取一个文本文件的内容? 这里介绍一种简便的读取一个文本文件的方法:
<!--Start of ASP Code---->
<%
'by James Seymour, http://jamesdot.org
Dim write
Dim fileSysObj, tf, read
' 读取文本read.txt
'获得文件名字
read = "read.txt"
'读取文件的完整路径
read = LEFT(Server.Mappath(Request.ServerVariables("PATH_INFO")), InStrRev(Server.Mappath
(Request.ServerVariables("PATH_INFO")), "\")) & read
'新建一个fileSysObj对象
Set fileSysObj = createObject("Scripting.FileSystemObject")
'读取整个文本文件
IF (fileSysObj.FileExists(read)) Then
'如果文件存在,则打来并读取文件
Set tf = filesysobj.OpenTextFile(read, 1)
read = tf.ReadLine
tf.Close
ELSE
'如果找不到read.txt文件,则显示下面的信息!
read = "I can't find the file read.txt! So this is my default message."
END IF
%>
'在下面表格中显示read.txt
<div align="center">
<center>
<table border="0" width="40%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" bgcolor="#EEEECC"><%=read%>
</td>
</tr>
<tr>
<td width="100%">
<!-- End of the ASP -->
使用上面的代码,点击并移动你的鼠标,使代码变成反白。使用右键中的“copy”命令复制这些代码。现在你就可以将这些代码粘贴到你的编辑器。

<!--Start of ASP Code---->
<%
'by James Seymour, http://jamesdot.org
Dim write
Dim fileSysObj, tf, read
' 读取文本read.txt
'获得文件名字
read = "read.txt"
'读取文件的完整路径
read = LEFT(Server.Mappath(Request.ServerVariables("PATH_INFO")), InStrRev(Server.Mappath
(Request.ServerVariables("PATH_INFO")), "\")) & read
'新建一个fileSysObj对象
Set fileSysObj = createObject("Scripting.FileSystemObject")
'读取整个文本文件
IF (fileSysObj.FileExists(read)) Then
'如果文件存在,则打来并读取文件
Set tf = filesysobj.OpenTextFile(read, 1)
read = tf.ReadLine
tf.Close
ELSE
'如果找不到read.txt文件,则显示下面的信息!
read = "I can't find the file read.txt! So this is my default message."
END IF
%>
'在下面表格中显示read.txt
<div align="center">
<center>
<table border="0" width="40%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" bgcolor="#EEEECC"><%=read%>
</td>
</tr>
<tr>
<td width="100%">
<!-- End of the ASP -->
使用上面的代码,点击并移动你的鼠标,使代码变成反白。使用右键中的“copy”命令复制这些代码。现在你就可以将这些代码粘贴到你的编辑器。