IO流大文件拷贝

 1 package com.test.io;
 2 
 3 import java.io.BufferedInputStream;
 4 import java.io.BufferedOutputStream;
 5 import java.io.File;
 6 import java.io.FileInputStream;
 7 import java.io.FileOutputStream;
 8 import java.io.IOException;
 9 
10 public class TestIO {
11     private static int BUFFER_SIZE = 8192;
12 
13     public static void main(String[] args) throws IOException {
14 
15         String resourcesPath="f:/a.grd";
16         String targetPath="d:/a.grd";
17         File resourcesFile = new File(resourcesPath);
18         File targetFile = new File(targetPath);
19         BufferedInputStream input = new BufferedInputStream(new FileInputStream(resourcesFile));
20         BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(targetFile));
21         try {
22             
23             byte[] buffer = new byte[BUFFER_SIZE];
24             int n = 0;
25             while (-1 != (n = input.read(buffer, 0, BUFFER_SIZE))) {
26                 output.write(buffer, 0, n);
27             }
28         } finally {
29             if (input != null) {
30                 input.close();
31             }
32             if (output != null) {
33                 output.close();
34             }
35         }
36     }
37 }
原文地址:https://www.cnblogs.com/bilaisheng/p/4976084.html