以下代码创建了一个文件,但它无法打开,并且它创建的文件大小与我尝试下载的文件的大小不远程对应。(以whatsapp updater 链接为例): private static boolean download(){ try { String outfile = "/sdcard/whatsapp.apk"; URL download = new URL("https://www.whatsapp.com/android/current/WhatsApp.apk"); ReadableByteChannel rbc = Channels.newChannel(download.openStream()); FileOutputStream fileOut = new FileOutputStream(outfile); fileOut.getChannel().transferFrom(rbc, 0, 1 << 24); fileOut.close(); rbc.close(); return true; } catch (IOException ioe){ return false; } }编辑:这是我完整代码的缩短版本,(完整代码允许主线程上的网络操作,并信任所有证书),也更改了问题中的代码。测试表明 IOException 没有被抛出,并且代码完成没有错误。那么,为什么下载的文件无法使用?
添加回答
举报
0/150
提交
取消