4
Answers

Cannot access file error

Ask a question
Konata Izumi

Konata Izumi

14y
2.8k
1
I am debugging a program that combines several wav files into one. This code always gives me an error message:

try
            {
                outFileStream = new FileStream(outputFile, FileMode.Create);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.GetBaseException().ToString());
            }

The error message is:

System.IO.IOException: The process cannot access the file 'C:\Documents and Settings\ .... \02.wav' because it is being used by another process.
  at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
  at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, FileShare share, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
  at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
  at System.IO.FileStream..ctor(String path, FileMode mode)
  at LiveDescribe.WavFile.writeAudioFileHeader(String outputFile, Boolean pStereo) in C:\Documents and Settings\ .... \WavFile.cs:line 503

note: line 503 is the line outFileStream = new FileStream(...)

How can I make it work?

Thanks.

Answers (4)