【发布时间】:2026-02-04 13:15:01
【问题描述】:
如何通过 url 从服务器下载音频文件并将其保存到 sdcard。
我正在使用下面的代码:
public void uploadPithyFromServer(String imageURL, String fileName) {
try {
URL url = new URL(GlobalConfig.AppUrl + imageURL);
File file = new File(fileName);
Log.d("ImageManager", "download begining");
Log.d("ImageManager", "download url:" + url);
Log.d("ImageManager", "downloaded file name:" + fileName);
/* Open a connection to that URL. */
URLConnection con = url.openConnection();
InputStream is = con.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is, 1024 * 50);
FileOutputStream fos = new FileOutputStream("/sdcard/" + file);
byte[] buffer = new byte[1024 * 50];
int current = 0;
while ((current = bis.read(buffer)) != -1) {
fos.write(buffer, 0, current);
}
fos.flush();
fos.close();
bis.close();
} catch (IOException e) {
Log.d("ImageManager", "Error: " + e);
}
}
上面的代码没有下载音频文件。 如果在清单文件中使用任何权限,请告诉我..(我使用了互联网权限) 请帮忙
谢谢..
【问题讨论】:
-
你怎么知道音频文件没有被下载?