HttpURLConnection conn = (HttpURLConnection) url.openConnection();
ReadableByteChannel rbc = Channels.newChannel(conn.getInputStream());
FileOutputStream fos = new FileOutputStream(fileName);
FileChannel fch = fos.getChannel();
fch.transferFrom(rbc, 0, Long.MAX_VALUE);
我调试了它,下载完成后到达下一行代码。如何获取在transferFrom()
写入文件、将其写入日志或控制台期间写入的字节数?
像这样的东西
while (len = fch.getWriteBytes()) {
System.out.println(len + " bytes : " + (len/total)*100 + "%");
}
抱歉,问题不完整。