<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 我都把程序关掉了,应该什么都释放掉了吧
__________________________________________________________________________
文件读写问题
用 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 我都把程序关掉了,应该什么都释放掉了吧
__________________________________________________________________________