问题描述
请尝试将代码循环的结果写入硬盘上的文本文件.我收到一个IOEXECPTION错误,您尝试访问的文件当前已被另一个进程使用.
子Main()
使用myreader作为StreamReader = New StreamReader("C:\ Users \ Jamiebones \ Desktop \ learning_application \ learning_application \ Phone Number.txt")
虽然不是(myreader.EndOfStream)
暗线作为字符串= myreader.ReadLine
昏暗的strBuilder作为新的Text.StringBuilder
如果String.IsNullOrEmpty(line)= False,而且行长度> gt; 1然后
strBuilder.Append("234")
strBuilder.Append(line.Remove(0,1))
如果结束
Console.WriteLine(strBuilder.ToString)
如果strBuilder.Length> 0 =则为真
昏暗的作家作为StreamWriter =新的StreamWriter("c:/电话号码.txt")
writer.Write(strBuilder.ToString)
如果结束
writer.closestream()
结束时
Console.ReadLine()
最终使用
引发此错误的代码行是"writer.Write(strBuilder.ToString)"
谢谢
Please i am trying to write the result of a loop in my code into a text file that on the harddisk. I am getting an IOEXECPTION error that the file you are trying to access is currently used by another process.
Sub Main()
Using myreader As StreamReader = New StreamReader("C:\Users\Jamiebones\Desktop\learning_application\learning_application\Phone Number.txt")
While Not (myreader.EndOfStream)
Dim line As String = myreader.ReadLine
Dim strBuilder As New Text.StringBuilder
If String.IsNullOrEmpty(line) = False AndAlso line.Length > 1 Then
strBuilder.Append("234")
strBuilder.Append(line.Remove(0, 1))
End If
Console.WriteLine(strBuilder.ToString)
If strBuilder.Length > 0 = True Then
Dim writer As StreamWriter = New StreamWriter("c:/phone numbers.txt")
writer.Write(strBuilder.ToString)
End If
writer.closestream()
End While
Console.ReadLine()
End Using
The line of code that throws this error is "writer.Write(strBuilder.ToString)"
Please i need help on this.Thanks
推荐答案
这篇关于请帮助IOEXCEPTION错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!