怎样读取一个文本文件的内容?
2006-10-28 00:00
369 查看
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.
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.
相关文章推荐
- 怎样读取一个文本文件的内容? (zt)
- 怎样读取一个文本文件的内容?
- c语言,读取一个内容长度未知的文本文件。
- LINUX C实现读取一个文本文件并返回其中最长的行的内容
- shell脚本----读取一个文本文件将内容按行保存成数组变量
- Java一次读取文本文件所有内容
- 怎样使jar包里的类能读取同在此jar包中的一个配置文件
- 谷歌浏览器怎样把网页全部内容保存为一个文件
- 读取Android Assets文本文件中的内容
- 一个C++按行读取Unicode 文本文件的例子
- 将多个文本文件的内容合并为一个文件的Java实现
- 怎样建一个登录,使其只能读取某个数据库的某个表?
- . <WP7>读取工程中的一个文件内容
- java 怎样向一个已存在的文件中添加内容
- Java案例:读取文本文件部分内容
- WPF中怎样将一个Textbox中的内容保存为txt【附源代码】
- java快速读取文本文件最后一行数据内容
- Java一次读取文本文件所有内容(已知文件编码)
- golang语言实现读取csv文件内容,把相同的内容提取到另外一个文件
- 如何启动一个命令,如何读取程序的一些内容和写一些东西到该进程中?