1

I am trying to read and write metadata to/from an mp3 file. I can read the data, but I cannot figure out how to write it.

I use the following code to get file access:

FileConnection file = (FileConnection) Connector.open("file:///store/home/user/music/song.mp3");
if(file.exists())
         java.io.InputStream inputStream = file.openInputStream();

Later, I read the data using the following code:

buffer = new byte[length]; // length is predetermined earlier
if (inputStream.read(buffer, 0, length) == length)
         String info = new String((buffer));

How do I write data (bytes) to the a designated location in the file? I am unsure of both the IO declarations and the specific code required to output my bytes.

Jasper
  • 2,166
  • 4
  • 30
  • 50
Julia
  • 11
  • 2

1 Answers1

0

To write a file on Blackberry use the following code:

    FileConnection fconn = null;
    OutputStream out = null;
    try {
        fconn = (FileConnection) Connector.open(yourFileNameAndPath,Connector.READ_WRITE);
    }
    fconn.create();
    out = fconn.openOutputStream();
    out.write(yourDataBytes);
    out.flush();
    fconn.close();
Farid Farhat
  • 2,300
  • 1
  • 16
  • 29