[VB.NET]文件读写问题

VB.NET源码-156个实用实例哦…… <script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
文件读写问题
用 vb.net print 方式写了一个 文本 文件
但是读取(vb.net) 该 文件的时候
要先在windows中 打开该文件 然后 点击保存(ctrl+S),再关闭
才能读取(vb.net),各位知道是什么原因吗?
__________________________________________________________________________
原因就是写错了。
Public Shared Sub Main()
Dim path As String = "c:/temp/MyTest.txt "

Try
If File.Exists(path) Then
File.Delete(path)
End If

Dim sw As StreamWriter = New StreamWriter(path) ''
sw.WriteLine( "This ")
sw.WriteLine( "is some text ")
sw.WriteLine( "to test ")
sw.WriteLine( "Reading ")
sw.Close()

Dim sr As StreamReader = New StreamReader(path)

Do While sr.Peek() > = 0
Console.WriteLine(sr.ReadLine())
Loop
sr.Close()
Catch e As Exception
Console.WriteLine( "The process failed: {0} ", e.ToString())
End Try
End Sub
__________________________________________________________________________
看看你写文本的时候是否有该该释放的没有释放
__________________________________________________________________________
Dispose释放掉就可以读了的。
__________________________________________________________________________
同意楼上观点
__________________________________________________________________________
问题就是这么简单!
__________________________________________________________________________
ps 我都把程序关掉了,应该什么都释放掉了吧
__________________________________________________________________________
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值