例子

字节处理流拷贝文件

  1. import java.io.*;
  2. public class Main {
  3. public static void main(String[] args) throws Exception {
  4. String srcPath = "./story.txt";
  5. String copyPath = "./story_copy1.txt";
  6. BufferedInputStream bis = new BufferedInputStream(new FileInputStream(srcPath));
  7. BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(copyPath));
  8. byte[] buffer = new byte[2048];
  9. int readLen = 0;
  10. while ((readLen = bis.read(buffer)) != -1) {
  11. bos.write(buffer, 0, readLen);
  12. }
  13. bis.close();
  14. bos.close();
  15. }
  16. }