前端之家收集整理的这篇文章主要介绍了
[VB.NET]文件读写问题,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
文件读写问题 用 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 我都把程序关掉了,应该什么都释放掉了吧 __________________________________________________________________________