日期:2014-05-17  浏览次数:20887 次

asp读写文件
最近要做一个功能就是有一个大文本框,提交过来之后,我要在服务器端的一个文本文件内把这次的内容写进去,然后我要在后台将其文本文件的所有文件读出,由于我原来是做jsp的这次突然要改这个asp的东西,所以请各位大侠多帮帮小弟我的忙,不胜感激,分数绝不亏待,最好有代码参考,或者给个例子。谢谢谢

------解决方案--------------------
append
-------------------------------
Sub OpenTextFileTest
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f
Set fso = CreateObject( "Scripting.FileSystemObject ")
Set f = fso.OpenTextFile( "c:\testfile.txt ", ForWriting, True)
f.Write "嗨,你好! "
f.Close
End Sub

read
---------------------
Function ReadAllTextFile
Const ForReading = 1, ForWriting = 2
Dim fso, f
Set fso = CreateObject( "Scripting.FileSystemObject ")
Set f = fso.OpenTextFile( "c:\testfile.txt ", ForWriting, True)
f.Write "世界你好! "
Set f = fso.OpenTextFile( "c:\testfile.txt ", ForReading)
ReadAllTextFile = f.ReadAll
End Function

详细参见
http://doc.51windows.net/vbscript/?url=/vbscript/dir.htm
------解决方案--------------------
<% Dim fso Dim str Dim Path Dim txt const ForAppending =8 const ForReading = 1 const TristateFalse = 0 const ForWriting = 2 Path = Server.MapPath( "aa.txt ") Set fso = Server.CreateObject( "Scripting.filesystemobject ") str = Request.Form( "name ") str = "DFSFSD " 'Response.Write(path) set txt = fso.OpenTextFile(Path,ForAppending,true) txt.Write(str) txt.close set txt = fso.OpenTextFile(path,ForReading,true) Response.Write(txt.ReadAll()) txt.close set txt= nothing set fso = nothing %>
------解决方案--------------------
类似功能做成一个类比较酷, 我的文件类里的读取写入函数
JScript:

function fAdoStmSvToFl_TxFl(sStr, sPath, nParam, sCharset){
if(!nParam)nParam=1;
var oStm=new ActiveXObject( 'adodb.stream ');
with(oStm){
type=2;
mode=3;
if(sCharset){
Charset=sCharset;
}
Open();
WriteText(sStr);
SaveToFile(sPath, nParam);
Close();
}
oStm=null;
} // end function fAdoStmSvToFl_TxFl // shawl.qiu code

function fStmRead(sPath, sCharset){
var o=new ActiveXObject( 'adodb.stream ')
with(o){
Type=2;
Mode=3;
Open;
LoadFromFile(sPath);
var pNum=0
if(typeof sCharset!= 'undefined '){
CharSet=sCharset;
if(sCharset== 'utf-8 '||sCharset== 'unicode ')pNum=2;
}
Position=pNum
$str=ReadText();
close;
}
o=null;
return $str
} // end function fStmRead(sPath, sCharset) // shawl.qiu code