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


来源:   

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

编辑:

相关内容

 娱乐专题

more...

高峰私生子

王伯昭被打

傅彪肝癌晚期

赵薇餐馆打人事件

《云南映象》图集

张铁林拖欠中介费

女医生状告赵忠祥

高虎被捕事件

演绎经典美丽

解读《十面埋伏》

揭示明星美丽秘诀

五颜六色娱乐圈

明星纤体大比拼

《绿茶》精彩影评

天地英雄

吕丽萍群星艺术学校被起诉

于娜出道前被包养是真是假?

香港英皇贪污丑闻追踪

多少明星追忆中

2003环球小姐大赛

 

 叨叨专栏

more...

冯小刚,你怎么敢抽"上帝"?

流氓与流氓

娱乐媒体,请站直一点

原来张铁林不是中国人!

《神雕侠侣》的悲惨前途

男人,要硬派不要阴柔

请不要随便脱裤子

李欣,《自娱自乐》的挺滋儿!

不服没用,人家就是红了!

陆毅演戏吧,别唱歌了。

 

 

 
报业集团
- 版权声明 - 广告业务 - 联系方式
Copyright (C) 2001-2002 dzwww.com. All Rights Reserved
大众报业集团网络中心主办
Email:webmaster@mail.dzdaily.com.cn