作家
登录

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

作者: 来源:www.28hudong.com 2013-03-30 08:55:21 阅读 我要评论

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

  推荐阅读

  设计 FileSystemObject

要用 FileSystemObject (FSO) 对象模式来编程,则: 1使用 CreateObject 方法来创建 FileSystemObject 对象。 2在新创建的对象上使用适当的方法。 3访问对象的属性。 FSO 对象模式包含在 Scripting 类型库中,该>>>详细阅读


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

地址:http://www.17bianji.com/kaifa2/ASP/32979.html

关键词: 探索发现

乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

网友点评
自媒体专栏

评论

热度

精彩导读
栏目ID=71的表不存在(操作类型=0)