怎么把文件中的内容显示出来??

luckyum 2004-06-22 04:02:09
如下是我的代码,页面会像死了一样很慢,不知什么原因
<%@LANGUAGE="VBSCRIPT" CODEPAGE="932"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--#include file="./Init.asp"-->
<%
dim str ,str_File
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
set objFSO = Server.CreateObject("Scripting.FileSystemObject")
set objTStream = objFSo.OpenTextFile("c:\PkgClnup.txt",ForReading)'每次好像到这都会死循环。
do while not objTStream.AtEndOfStream
response.Write(objTStream.ReadLine)
Loop
objTStream.close
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis">
</head>

<body>
</body>
</html>
...全文
141 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
sxsgssgs 2004-06-22
  • 打赏
  • 举报
回复
上面已经有答案了。
luckyum 2004-06-22
  • 打赏
  • 举报
回复
我在日文下 jis编码
fashchina 2004-06-22
  • 打赏
  • 举报
回复
不会吧,我都好好的
luckyum 2004-06-22
  • 打赏
  • 举报
回复
这么写他只会显示第一个字符,跳出循环了



<%@LANGUAGE="VBSCRIPT" CODEPAGE="932"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
'dim str ,str_File,read
ServerPath = Server.MapPath("/CADWeb/")
filepath1 = ServerPath & "\PkgClnup.txt"

Set fso = CreateObject("Scripting.FileSystemObject")
IF fso.FileExists(filepath1) Then
Set txt = fso.OpenTextFile(filepath1,1)

do while not txt.atEndOfStream
read=txt.readline
Response.write( read & "<br>")
loop
txt.Close
ELSE
read = "找不到文件"

END IF
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis">
</head>

<body>
</body>
</html>
fashchina 2004-06-22
  • 打赏
  • 举报
回复
up
Set fileSysObj = createObject("Scripting.FileSystemObject")
IF (fileSysObj.FileExists(filepath1)) Then
' Set ts=fileSysObj.OpenTextFile(filepath1)
'' content=ts.Readall&vbcrlf&content
' ts.close
'response.Write content


'如果文件存在,则打来并读取文件
Set tf = filesysobj.OpenTextFile(filepath1)
'read= tf.Readall
'Do While not tf.atEndOfStream
'read = tf.Readall
'Response.write read & "<br>" '逐行读文件并写出
'Loop
do while not tf.atEndOfStream
read=tf.readline
Response.write read & "<br>" '逐行读文件并写出
loop
tf.Close
ELSE
'如果找不到read.txt文件,则显示下面的信息!
read = "找不到文件"

END IF
luckyum 2004-06-22
  • 打赏
  • 举报
回复
这个问题比较急,麻烦大家了,不够可以加分
luckyum 2004-06-22
  • 打赏
  • 举报
回复
我正在测试,如果成功迅速接贴
我照书上写的会出错
按照网上的文章也会出错。
我把大多的代码都精简掉就剩下
这样会死掉
<%
set objFSO = Server.CreateObject("Scripting.FileSystemObject")
set objTStream = objFSo.OpenTextFile("c:\PkgClnup.txt",ForReading)
objTStream.close
%>
这样会打出aaa,他好像就到OpenTextFile死掉的。
<%
set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'set objTStream = objFSo.OpenTextFile("c:\PkgClnup.txt",ForReading)
response.write("aaaaa")
'objTStream.close
%>
goodera 2004-06-22
  • 打赏
  • 举报
回复
whichfile=server.mappath("yx.txt")
Set fso = CreateObject("Scripting.FileSystemObject")
Set txt = fso.OpenTextFile(whichfile,1)
rline = txt.ReadLine
do while not txt.atendofstream
rline = rline & "<br>" & txt.ReadLine
loop
txt.close



介个简单啊~---方言?呵呵
rtsp 2004-06-22
  • 打赏
  • 举报
回复
<%

function FSOFileRead(filename)
Dim objFSO,objCountFile,FiletempData
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objCountFile = objFSO.OpenTextFile(filename,1,True)
FSOFileRead = objCountFile.ReadAll
objCountFile.Close
Set objCountFile=Nothing
Set objFSO = Nothing
End Function

Xml_File_Name = "c:\test.txt"

response.write FSOFileRead(Xml_File_Name)

%>
tutu944 2004-06-22
  • 打赏
  • 举报
回复
whichfile=server.mappath("yx.txt")
Set fso = CreateObject("Scripting.FileSystemObject")
Set txt = fso.OpenTextFile(whichfile,1)
rline = txt.ReadLine
do while not txt.atendofstream
rline = rline & "<br>" & txt.ReadLine
loop
txt.close

介个简单啊~
lawdoor 2004-06-22
  • 打赏
  • 举报
回复
循环的时候没有将指针移动到下一条记录,一直在一个位置无休止循环
<%
do while not rs.eof
................
..........
................
rs.movenext
loop
%>
lawdoor 2004-06-22
  • 打赏
  • 举报
回复
循环语句错误!
<%
do while not objTStream.AtEndOfStream
................
..........
................
rs.movenext
loop
%>
银狐被占用 2004-06-22
  • 打赏
  • 举报
回复
是不是你的文件太大了?

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧