What i am trying to do it write a text file, and then immediately after, read it. The problem is, is that i am getting an error saying that the file is in use by another application. What can i do to fix this?
Printable View
What i am trying to do it write a text file, and then immediately after, read it. The problem is, is that i am getting an error saying that the file is in use by another application. What can i do to fix this?
If you just wrote to the file, it cant be in use by another application, maybe you havent closed the stream that wrote to it...
This should work as is and can be called one after the other...
Code:Private Sub writetextfile(byval strText() as string,path)
dim w as new IO.streamwriter(path)
for each s as string in strText
w.writeline(s)
next
w.close
End Sub
Private Function ReadTextFile(byval path as string)as list(of string)
dim s as new list(of string)
dim r as new IO.streamreader(path)
s.addrange(r.ReadAllLines)
r.close
return s
end function
how would i close this?:
Code:My.Computer.FileSystem.WriteAllText("C:\Users\Ethan Hayon\Desktop\test8.txt", _
nwlinestring, False)
Sorry dude, I have never seen that before, try the function I typed earlier, it will be just as fast, and you can read it and see which lines of code throw erros, not that it should...
dont forget to check if the file exists, and set write mode, either append or create new...
okay, ill try that, thanks
Why would you want to write to a file and read it directly afterwards? You should already have the information that has been put in the file, unless its been changed by an external application.
I was actually wondering that myself...
Trying to justify a good reason for doing so, but im not coming up with any, whats the purpose of this?
I have actually needed to do this myself once but I also called another application (using shell) between re-opening and passed the text file path as a parameter for spell checking, and then tried to re-open it...
i need to read an array an pull out certain lines, the only way that i could get to work is by writing a text file and re reading it line by line
Check my post in your thread about that.... you dont have to write it out first...
OK, what are the charectoristics of the lines you want to pull out of this array.?
Is there any thing that sets them apart from the rest?
(I guess there has to be)..
BTW: have you tried using
List(of string) instead of a string array, its heaps better and easier to use...