(VB.NET、.NET 3.5)奇妙な "IOExceptionが処理されませんでした"
私は次の関数を書いてtxtファイルからテキストを読みました。それはうまくいきましたが、今はそうではありません。それは「にIOExceptionが未処理だった」私は、このエラーメッセージ
を与え、
続ける「『F:\ kh_matt \ ch1.txt』プロセスはファイルにアクセスできません。それは別のプロセスによって使用されているため」
ch1.txtは、どのプログラムでも開いていたり、全く使用されていません。私はch1.txtを別の場所(ドライブD)に移動しようとしましたが、同じメッセージエラーが発生しましたが、別の場所でのみ使用されているため、プロセスはファイル 'D:\ ch1.txt'にアクセスできません。
がプライベートサブbtnRead_Click(System.ObjectのとしてByVal送信者、System.EventArgsとしてByVal e)はbtnRead.Click
ハンドルDim reader As StreamReader
Dim filelocation As String
filelocation = "F:\kh_matt\ch1.txt"
Dim chid As Integer
chid = 1
If System.IO.File.Exists(filelocation) = True Then
reader = New StreamReader(New FileStream(filelocation, FileMode.Open))
Else
MsgBox(filelocation, MsgBoxStyle.OkOnly)
End If
Dim MyStream As New StreamReader(Path.Combine(Application.StartupPath, filelocation))
Dim vArray() As String = MyStream.ReadToEnd.Split(CChar("$"))
MyStream.Close()
Dim count As Integer
For d As Integer = 0 To vArray.Length - 1 Step 1
If d = vArray.Length - 1 Then
Exit For
End If
InsertKh(chid, d + 1, vArray(d))
count = d + 1
Next
MsgBox("Done Inserting")
End Sub
それは、常にこのコードを指す:「
は、ここに私のコードブロックです:dim M新しいStreamReaderとしてのyStream(Path.Combine(Application.StartupPath、filelocation))
ここで、それぞれのボタンをデバッグして押します。誰が問題が何であるかを指摘できますか?ありがとう
そうです。今私は、このコードブロックをコメントアウト: 'System.IO.File.Exists(のFileLocationは)= TRUEなら、 ' リーダー=新しいStreamReaderを(新しいFileStreamを(のFileLocation、FileMode.Open)) 'エルス ' のMsgBox(のFileLocation 、MsgBoxStyle.OkOnly) 'End If –