怎样读取一个文本文件的内容
类别: ASP教程
<%
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%">
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%">
- 上一篇: 得到表中字段属性代码
- 下一篇: ASP中巧用RESPONSE属性
-= 资 源 教 程 =-
文 章 搜 索