Question

Apologies, I am very new to BlackBerry development. All I need to do is save an mp3 file (which I download from a HTTP server), and then play it back. I have most of the code done, but I keep getting a file system error 1003. (I have to use BlackBerry JDE 4.5.0).

try {
    FileConnection fconn = (FileConnection) Connector.open( "file://data/myfile.mp3", Connector.READ_WRITE );
    final HttpConnection connection = (HttpConnection) Connector.open("http://som.server.com/andFile.mp3;interface=wifi");

    if (!fconn.exists()) {
        fconn.create();
    } else {
        fconn.delete();
        fconn = (FileConnection) Connector.open( "file://data/myfile.mp3", Connector.READ_WRITE );
        fconn.create();
    }

    final InputStream inputStream = connection.openInputStream();
    final StringBuffer buffer = new StringBuffer();

    try {
        int ch;
        while ( ( ch = inputStream.read() ) != -1 ) {
            buffer.append( (char) ch );
    } finally {
        inputStream.close();
        connection.close();
    }

    fconn.setWritable(true);

    final OutputStream outputStream = fconn.openOutputStream();
    outputStream.write(buffer.toString().getBytes());
    outputStream.close();
} catch (Exception e) {
    System.out.println(e.getMessage());
}


final Player mPlayer;
final VolumeControl vc;
final InputStream is = getClass().getResourceAsStream("data/myfile.mp3");

try {
    mPlayer = Manager.createPlayer(is, "audio/mpeg");
    mPlayer.addPlayerListener(WelcomeScreen.this);
    mPlayer.realize();
    mPlayer.prefetch();

    vc = (VolumeControl) mPlayer.getControl("VolumeControl");
    vc.setLevel(50);

    mPlayer.start();
} catch (Exception e) {
    System.out.println(e.getMessage());
}

In the above code I just try to play the file I save, but it I get the file system error. I did check on the device, and it seems that the file was actually properly saved once.

What is the correct path that I should use to save files under the application data folder?

Was it helpful?

Solution

Check this article

There is explained how to compose file path for files you want to save to device memory or memory sd card.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top