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