Click here to Skip to main content
12,760,727 members (33,676 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB 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(line.Remove(0, 1))
End If

If strBuilder.Length > 0 = True Then
Dim writer As StreamWriter = New StreamWriter("c:/phone numbers.txt")

End If

End While

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
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 "/".

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 21 Nov 2012
Copyright © CodeProject, 1999-2017
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