<%@ import namespace="system.io" %> '引入所需的namespace <% response.write("writing the content into text file in asp.net <br>") dim strwriterobj as streamwriter '声明一个streamwriter对象 strwriterobj= file.createtext("c:/aspnet.txt") '新建一个文本文件,赋值给streamwriter对象 strwriterobj.writeline( "welcome to wonderfull world of asp.net programming" ) '向文件中写内容 strwriterobj.close '关闭对象 response.write("done with the creation of text file and writing content into it") %>
2、读文件 readfile.aspx
<%@ import namespace="system.io" %> <% response.write("reading the content from the text file aspnet.txt <br>") dim streamreaderobj as streamreader '声明一个streamreader对象 dim filecont as string '声明一个变量保存读出的内容 streamreaderobj = file.opentext( "c:/aspnet.txt" ) '打开文件赋值到streamreader对象 do '按行循环读取文件内容 filecont = streamreaderobj.readline() response.write( filecont & "<br>" ) loop until filecont = "" streamreaderobj.close '关闭streamreader对象 response.write("<br> done with reading the content from the file aspnet.txt") %>