2

My blackberry application has some mp3 files bundled with the application. I want to add these files from the app to a folder in the sdcard or a folder in my phone memory through program.

How can I do this? Is it possible?

Thanks.

Maksym Gontar
  • 22,765
  • 10
  • 78
  • 114
lostInTransit
  • 70,519
  • 61
  • 198
  • 274

1 Answers1

2

It is possible, open the resources as a stream:

String fileName = "/myPath/myFile.mp3";
InputStream inputStream = getClass().getResourceAsStream(fileName);

Then read the stream and write it out to a file:

String locator = "file:///SDCard"+fileName;
FileConnection saveFile = (FileConnection)Connector.open(locator);
saveFile.create();
OutputStream outputStream = saveFile.openOutputStream();

I'm sure you can loop over inputStream to copy it to outputStream, then close.

Maksym Gontar
  • 22,765
  • 10
  • 78
  • 114
Richard
  • 8,920
  • 2
  • 18
  • 24