|
-
Nov 16th, 2001, 05:42 PM
#1
Thread Starter
Hyperactive Member
file in use error
I am using this loop several times in my app
Dim X As Short
For X = 1 To 5
Dim FSO As File
Dim FStreamObject As FileStream
FSO.Create(Application.StartupPath & "\" & X & ".txt")
FSO.SetAttributes(Application.StartupPath & "\" & X & ".txt", FileAttributes.Archive)
Next
It works fine the first time I go throught the loop. The problem is when it goes through the loop a second time, it generates the error "The process cannot access the file "C:\1.txt" because it is being used by another process.
Is there a way to release the handle on the file?
Also, I found how to write a byte array to a text file, but how do I write a string type?
Thanks
-
Nov 18th, 2001, 10:14 PM
#2
Dim fFile as File works fine the first time, but generates an error if you use it a second time. It has no Close method.
You can use this
'To create a file
Dim fFileStream as FileStream = new FileStream("c:\test.txt", FileMode.Create)
'to write to a file
Dim fStreamWriter as StreamWriter = New StreamWriter("c:\test.txt")
fStreamWriter.Write("I am writing to the file now!" & vbcrlf)
'this will release the applications "Grip" on the file
fStreamWriter.Close
'to read from a file
'dim fStreamReader as StreamReader = New StreamReader("c:\test.txt")
Messagebox.Show(fStreamReader.ReadLine())
'this will release the applications "Grip" on the file
fStreamReader.Close
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|