我有一個視頻文件(.MP4格式),我想,讓用戶能夠將視頻下載到他們的SD card.I目前使用此代碼,但它不工作..如何將視頻文件下載到SD卡?
String PATHSdcard = "/sdcard/Video/";
public void DownloadFromUrl(String VideoURL, String fileName)
try { URL url = new URL("https://javmed-prod.s3.amazonaws.com/666034cbe81045f2a2da50e5205e376b.mp4");
File file = new File(fileName);
long sTime = System.currentTimeMillis();
URLConnection URLcon = url.openConnection();
InputStream is = URLcon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
FileOutputStream fos = new FileOutputStream(PATHSdcard+file);
fos.write(baf.toByteArray());
fos.close();
} catch (IOException e) {
Log.d("ERROR.......",e+"");
}
謝謝你的幫助!
那你前面試試? – user370305
視頻的來源在哪裏?它是否託管在http服務器中? – momo
http://stackoverflow.com/questions/3692252/android-how-do-i-download-a-video-file-to-sd-card可能重複。 –