Android下載二進制文件問題我在從我的應用程序中下載二進制文件(視頻)時遇到問題。在Quicktime中,如果我直接下載它可以正常工作但通過我的應用程序不知何故它搞砸了(即使它們在文本編輯器中看起來完全相同)。這是一個例子: URL u = new URL("http://www.path.to/a.mp4?video");
HttpURLConnection c = (HttpURLConnection) u.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
FileOutputStream f = new FileOutputStream(new File(root,"Video.mp4"));
InputStream in = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ( (len1 = in.read(buffer)) > 0 ) {
f.write(buffer);
}
f.close();
添加回答
舉報
0/150
提交
取消