我在从我的应用程序中下载二进制文件(视频)时遇到问题.在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();
Run Code Online (Sandbox Code Playgroud)