Tôi có một tập tin video (MP4 định dạng) và tôi muốn cho phép người dùng có thể tải về các video sang SD card.I của họ hiện đang sử dụng mã này, nhưng nó không làm việc ..Tôi làm cách nào để tải tệp video xuống thẻ 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+"");
}
Cảm ơn vì bất kì sự giúp đỡ!
bạn đã thử làm gì trước? – user370305
nguồn của video ở đâu? Nó có được lưu trữ trên máy chủ http không? – momo
http://stackoverflow.com/questions/3692252/android-how-do-i-download-a-video-file-to-sd-card có thể trùng lặp. –