Search code examples
blackberryfile-iojava-meresourcesjsr75

Blackberry - Adding mp3 files to an sdcard folder from application resources


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.


Solution

  • 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.