【发布时间】:2018-04-28 18:27:33
【问题描述】:
我遇到了这个问题,它似乎并没有消失。我在 vb.net 中完成了一个代码,我在其中流式传输文件,但我不断收到该错误
“IOException was unhandled”进程无法访问文件 'C:\Users\Lenovo\documents\visual studio 2010\Projects\File streaming\File Streaming\bin\Debug\banking.xls' 因为它正在 被另一个进程使用。
代码如下:
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()
**ERROR APPEARS HERE**
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
【问题讨论】:
-
哪里有 C++?
-
对不起,没有 c++,或者我认为。我还是新人,所以我不知道准确
-
把你的流放在 Using 语句中,以确保一切都正确关闭。有时打开相同的文件会导致问题。是否有其他进程试图打开该文件?
-
您是否在 Excel 中打开了文件?
-
the_lotus 我试图理解你在说什么,记住我对 vb 非常陌生
标签: vb.net