
set fs=server.createobject("scripting.filesystemobject")
file=server.mappath("read.txt")
set txt=fs.opentextfile(file,1,true)
if not txt.atendofstream then
line=txt.ReadAll
response.write line &"<br>"
end if
%>
line=txt.ReadLine'从文件中读取N个字节的数据
line=txt.Read(N)'从文件中读取一行数据
直接用静态类file的ReadAllLines(string path)函数,他返回以行为单元的字符串数组string[] arr第三行就是 arr[2] 一千行就是arr[999]
如果想从指定位置读取
可以创建filestream对象,然后用seek()方法指定文件指针位置,基于此对象的streamreader就可以从指定位置读取数据。
读取:string path = Server.MapPath("婚不由己.txt")
string txt= File.ReadAllText(path, Encoding.Default)
txtcon.Text=txt
存储:
string path = Server.MapPath("婚不由己.txt")
StreamWriter sw = new StreamWriter(path)
sw.Write(txtcon.Text)//TextBox2中的文本是可以编辑后的。
sw.Close()
sw.Dispose()
然后在config文件中设置节点:
<httpRuntime requestValidationMode="2.0" />
<pages validateRequest="false">,应该是的,这两个不设置,不调试的时候,会报错,你看下错。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)