欢迎光临
我们一直在努力

怎样读取一个文本文件的内容?

建站超值云服务器,限时71元/月

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

<!–start of asp code—->

<%

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 cant find read.text, display default message

read = "i cant 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%">

<!– end of the asp –>

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.

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 怎样读取一个文本文件的内容?
分享到: 更多 (0)