public class DownloadVoiceThread extends Thread {
private String urlStr; //下载链接
private String filePath; //文件全路径,包含文件名以及各式
private String fileName; //文件名
private String SDCard; //文件存储地址
private File f_voice;
public DownloadVoiceThread(String urlStr, String filePath, String fileName,
String SDCard) {
this.urlStr = urlStr;
this.filePath = filePath;
this.fileName = fileName;
this.SDCard = SDCard;
}
public void run() {
OutputStream output = null;
try {
File f_voice = new File(filePath);
Log.i("文件地址", filePath);
InputStream input = conn.getInputStream();
int len=conn.getContentLength();
if (f_voice.exists()) {
System.out.println("exits");
return;
} else {
// String dir = SDCard + "/" + path;
new File(SDCard).mkdir();// 新建文件夹
f_voice.createNewFile();// 新建文件
output = new FileOutputStream(f_voice);
// 读取大文件
byte[] voice_bytes = new byte[1024];
int len1 = -1;
while ((len1 = input.read(voice_bytes)) != -1) {
output.write(voice_bytes, 0, len1);
output.flush();
}
System.out.println("success");
output.close();
}
} catch (Exception e) {
System.out.println(e.toString());
e.printStackTrace();
//return;
} finally {
}
}
}
android 音频文件下载
最新推荐文章于 2021-05-27 02:18:22 发布