抱歉,我对黑莓开发很陌生。我需要做的就是保存一个 mp3 文件(我从 HTTP 服务器下载),然后播放它。我已经完成了大部分代码,但我不断收到文件系统错误 1003。(我必须使用 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());
}
在上面的代码中,我只是尝试播放我保存的文件,但是我得到了文件系统错误。我确实检查了设备,似乎该文件实际上已正确保存一次。
我应该用来在应用程序数据文件夹下保存文件的正确路径是什么?