Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET IO
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
Posted 21-Nov-12 17:30pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

First the writer.Close (not CloseStream!) should be inside the If block directly above it, not after the End If.

Second, the path seperator character in Windows is "\", not "/".
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 383
1 Sascha Lefévre 215
2 Maciej Los 185
3 Abhinav S 170
4 Richard Deeming 155
0 Sergey Alexandrovich Kryukov 7,141
1 OriginalGriff 6,410
2 Maciej Los 2,832
3 Abhinav S 2,732
4 Peter Leow 2,694


Advertise | Privacy | Mobile
Web04 | 2.8.150414.1 | Last Updated 21 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100