1、写文件writefile.aspx
<%"引入所需的NameSpace%>
<%@ Import Namespace="System.IO" %>
<%
Response.write("将内容写入aspnet.txt文件中
")
"声明一个StreamWriter对象
Dim strwriterobj As StreamWriter
"新建一个文本文件,赋值给StreamWriter对象
strwriterobj= File.CreateText("c:\aspnet.txt")
"向文件中写内容
strwriterobj.WriteLine( "欢迎加入ASP.NET 开发的队伍!" )
"关闭对象
strwriterobj.Close
Response.write("文件成功写入")
%>
2、读文件readfile.aspx
<%@ Import Namespace="System.IO" %>
<%
Response.write("读取asp.net文件中的内容
")
"声明一个StreamReader对象
Dim streamreaderobj As StreamReader
"声明一个变量保存读出的内容
Dim filecont As String
"打开文件赋值到StreamReader对象
streamreaderobj = File.OpenText( "c:\aspnet.txt" )
"按行循环读取文件内容
Do
filecont = streamreaderobj.ReadLine()
If filecont="" Then
Response.Write( filecont )
Else
Response.Write( filecont & "
" )
End If
Loop Until filecont = ""
"关闭StreamReader对象
streamreaderobj.Close
Response.write("已经读完aspnet.txt文件的内容")
%>
3、删除文件Filedelete.aspx
<%@ Import Namespace="System.IO" %>
<%
"删除文件
File.Delete("c:\aspnet.txt" )
Response.write("aspnet文件被成功删除!" )
%>