views:

484

answers:

1

Hi

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.

+1  A: 

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.

Richard