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

发布时间:2022-04-17 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了怎样读取一个文本文件的内容?脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
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")), "\")) &amp; 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%">


<!-- 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.

脚本宝典总结

以上是脚本宝典为你收集整理的怎样读取一个文本文件的内容?全部内容,希望文章能够帮你解决怎样读取一个文本文件的内容?所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: