网络编程
位置:首页>> 网络编程>> Asp编程>> asp如何读取文本文件的内容?

asp如何读取文本文件的内容?

 来源:asp之家 发布时间:2009-11-18 20:55:00 

标签:文本,内容,asp

用下面代码可实现:

<%
Dim write
Dim fileSysObj, tf, read
read = "intels.txt"
' 读取intels.txt 
read = LEFT(Server.Mappath(Request.ServerVariables("PATH_INFO")), InStrRev(Server.Mappath(Request.ServerVariables("PATH_INFO")), "\")) & read
' 检索要读的文件的完整路径
Set fileSysObj = createObject("Scripting.FileSystemObject")
' 创建一个 FileSystem Object 实例,并把它保存到 fileSysObj 的变量中
IF (fileSysObj.FileExists(read)) Then
Set tf = filesysobj.OpenTextFile(read, 1)
' 如果文件在,就打开读取
read = tf.ReadLine
tf.Close
ELSE
read = "噢,找不到这个文件!"
' 如果文件不存在,发出错误提示
END IF
%>
<html>
<body>
<p align="center">精彩春风之读取文本内容</p>
<div align="center">
<div align="center">
<center>
<table border="0" width="40%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" bgcolor="green"><B><%=read%></B>
</td>
</tr>
<tr>
<td width="100%">
</table>
</center></div>
</body>
</html>

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com