Java缓冲流高效大文件的复制实例


public class BufferedDemo { public static void main(String[] args) throws FileNotFoundException { // 记录开始时间
long start = System.currentTimeMillis(); // 创建流对象
try ( BufferedInputStream bis = new BufferedInputStream(new FileInputStream("jdk8.exe")); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("copy.exe")); ){ // 读写数据
int len; byte[] bytes = new byte[8*1024]; while ((len = bis.read(bytes)) != -1) { bos.write(bytes, 0 , len); } } catch (IOException e) { e.printStackTrace(); } // 记录结束时间
long end = System.currentTimeMillis(); System.out.println("缓冲流使用数组复制时间:"+(end - start)+" 毫秒"); } } // 缓冲流使用数组复制时间:666 毫秒

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM