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());
}
在上面的代码中,我只是尝试播放我保存的文件,但是我收到了文件系统错误。我检查了设备,似乎文件实际上已正确保存一次。
我应该使用什么正确的路径来保存应用程序数据文件夹下的文件?