“Ioexception未处理”错误不断出现,我该如何摆脱这个错误 [英] “Ioexception was unhandled” that error keeps appearing, how do I get rid of this error
问题描述
我忙着尝试文件Streaming但我继续更加特别地伴随着上面提到的错误:
进程无法访问文件'C:\ Users\Lenovo \documents\visual studio 2010 \Projects\File streaming\File Streaming\bin\Debug\banking.xls'因为它正被另一个进程使用。
但该文件未被任何其他程序打开或使用
我尝试过:
进口 System.IO
Imports System.Windows.Forms.Form
公共 类 Form1
私有 Sub Form1_Load( ByVal sender As System。 Object , ByVal e As System.EventArgs) Handles MyBase .Load
End Sub
私有 Sub btnDisplay_Click(< span class =code-keyword> ByVal sender As System。 Object , ByVal e As System.EventArgs) Handles btnDisplay。点击
Dim FileStr As 新 FileStream( banking.xls,FileMode.Create,FileAccess.Write)
Di m a As 新 StreamWriter(FileStr)
' a.WriteLine(文件应显示在RTB ............)
' a.Close()
FileStr = 新 FileStream( banking.xls,FileMode.Open,FileAccess.Read)
Dim i As < span class =code-keyword> New StreamReader(FileStr)
i.BaseStream.Seek( 0 ,SeekOrigin。 开始)
如果 i.Peek()> -1 然后
rtbDisplay.Text& = i.ReadLine()
结束 如果
i.Close()
结束 Sub
私有 Sub btnClear_Click(sender As System。 Object ,e As System.EventArgs)句柄 btnClear.Click
rtbDisplay.Text =
结束 Sub
私有 Sub btnExit_Click(sender As System。 Object ,e As System.EventArgs)句柄 btnExit.Click
我 .Close()
结束 Sub
私有 功能 FileStream()作为 对象
投掷 新 NotImplementedException
结束 功能
结束 类
Quote:但该文件未被任何其他程序打开或使用
该文件未被其他进程打开但是你自己的应用程序!
您已经评论关闭
致电:
Dim FileStr As 新 FileStream( banking.xls,FileMode.Create,FileAccess.Write)
Dim a As New StreamWriter(FileStr)
' a.WriteLine(文件应显示在RTB ............)
' 必须取消注释!
' a.Close()
' 或者处理或关闭FileStream
FileStr.Dispose ()
' FileStr.Close()
' 文件仍然打开时失败
FileStr = 新 FileStream( banking.xls,FileMode.Open,FileAccess.Read)
I busy trying file Streaming but i keep on getting the above mentioned error more especially accompanied by:
"The process cannot access the file 'C:\Users\Lenovo\documents\visual studio 2010\Projects\File streaming\File Streaming\bin\Debug\banking.xls' because it is being used by another process."
but the file is not opened or used by any other program
What I have tried:
Imports System.IO
Imports System.Windows.Forms.Form
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
Dim FileStr As New FileStream("banking.xls", FileMode.Create, FileAccess.Write)
Dim a As New StreamWriter(FileStr)
'a.WriteLine("File should be displayed in the RTB............")
'a.Close()
FileStr = New FileStream("banking.xls", FileMode.Open, FileAccess.Read)
Dim i As New StreamReader(FileStr)
i.BaseStream.Seek(0, SeekOrigin.Begin)
If i.Peek() > -1 Then
rtbDisplay.Text &= i.ReadLine()
End If
i.Close()
End Sub
Private Sub btnClear_Click(sender As System.Object, e As System.EventArgs) Handles btnClear.Click
rtbDisplay.Text = ""
End Sub
Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Function FileStream() As Object
Throw New NotImplementedException
End Function
End Class
Quote:but the file is not opened or used by any other program
The file is not opened by another process but by your own application!
You have commented theClose
call:
Dim FileStr As New FileStream("banking.xls", FileMode.Create, FileAccess.Write) Dim a As New StreamWriter(FileStr) 'a.WriteLine("File should be displayed in the RTB............") ' This must be uncommented! 'a.Close() 'Or dispose or close the FileStream instead FileStr.Dispose() 'FileStr.Close() 'This fails when the file is still opened FileStr = New FileStream("banking.xls", FileMode.Open, FileAccess.Read)
这篇关于“Ioexception未处理”错误不断出现,我该如何摆脱这个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!