首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 网站建设 > ASP > 怎样读取一个文本文件的内容?
【标  题】:怎样读取一个文本文件的内容?
【关键字】:文件
【来  源】:网络

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

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.

清除浏览器历史记录代码:【上一篇】
asp.net高级教程(三)-对象:【下一篇】
【相关文章】
没有相关文章
【随机文章】
  • 本人对“xxx开发工作室”项目采用框架的聊天记录---个人看法
  • read-Atleap-9-新闻实体hibernate关系代码分析
  • stl----sort 与unique的调用次序和unique的用法
  • 搞定ListArrayInfoTag程序
  • [原创]比较用户目录是否超出设定值
  • 关于HtmlForm控件
  • XML简易教程之三
  • 实例讲解flashMTV制作全过程(7)
  • C语言函数大全(c开头)
  • 微软 WindowsMediaPlayer11发布[原创]
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.