0

hiiii, i want to read mp3 file by using binary reader, my code is :

using (BinaryReader br = new BinaryReader(File.Open("Songs/testbinary.mp3", FileMode.Open)))
        {
           int length = (int)br.BaseStream.Length;

            byte[] bytes = br.ReadBytes(length);

            txtBinary.Text = bytes.ToString();
        }

....... when i execute this code it shows and exception:

The process cannot access the file 'URL\testbinary.mp3' because it is being used by another process.

where "URL" is my actual file location.

Deepak
  • 178
  • 1
  • 2
  • 14

1 Answers1

1

You open the same file twice (without any sharing option). To read the content of a file as bytes you can use File.ReadAllBytes

byte[] bytes = File.ReadAllBytes("Songs/testbinary.mp3");

BTW: Don't forget txtBinary.Text = bytes.ToString(); doesn't give you what you think. You will have to use BitConverter.ToString or Convert.ToBase64String

EZI
  • 15,209
  • 2
  • 27
  • 33