1
Answer

Having real problems with BinaryWriter file access

Ask a question
Grimtaz

Grimtaz

18y
2.6k
1

Ok so I'm tearing my hair out.  I've been trying for the last 2hrs to get this thing to work like it's supposed to. I have a binary file which I need to create or overwrite multiple times because the data is changing frequently.

Here is the code I'm using:

BinaryWriter dataOut = new BinaryWriter(new FileStream(datfilename, FileMode.Create, FileAccess.Write));

dataOut.Write(data);
....
....
dataOut.Close();

It works first time. But when called a second time it gives the error "The process cannot access the file .... because it is being used by another process."

Thats rubbish! It's been closed!!

Can somone please help me out??


Answers (1)