Android 我想从服务器下载音频
我正在尝试使用android手机从服务器下载音频。 上面我使用的代码在android中不起作用。 有人知道原因吗?Android 我想从服务器下载音频,android,audio,download,Android,Audio,Download,我正在尝试使用android手机从服务器下载音频。 上面我使用的代码在android中不起作用。 有人知道原因吗? 非常感谢 你说的“不工作”是什么意思?哪个安卓版本?会引发什么异常?不工作意味着我无法使用这些代码下载音频。我使用的是安卓2.1版本。 private void doFileDownload() throws Exception { BufferedInputStream in = null; BufferedOutputStream out = null;
非常感谢 你说的“不工作”是什么意思?哪个安卓版本?会引发什么异常?不工作意味着我无法使用这些代码下载音频。我使用的是安卓2.1版本。
private void doFileDownload() throws Exception {
BufferedInputStream in = null;
BufferedOutputStream out = null;
String url = "http://www.jimsonmok.com/server/uploads/"; //input
String file = "/sdcard/Shek Kip Mei MTR Station Exit A.3gp"; //output
try{
url += URLEncoder.encode("Shek Kip Mei MTR Station Exit A.3gp");
URL download = new URL(url);
URLConnection downloadConnection = download.openConnection(); //set up connection
in = new BufferedInputStream(downloadConnection.getInputStream());
out = new BufferedOutputStream(new FileOutputStream(file));
int contentlength = downloadConnection.getContentLength(); //getting the length of the file
for(int counter=0;counter < contentlength;counter++) //storing the binary I/O file
out.write(in.read());
}catch(IOException e){
}
in.close();
out.close();
}