package com.apesblog.day_26;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class Test4 {
    public static void main(String[] args) {
        FileInputStream fileInputStream = null;
        FileOutputStream fileOutputStream = null;
        try {
            File file = new File("src/com/apesblog/day_26/1.png");
            File file2 = new File(file.getParent(), "copy.png");
            byte[] buffer = new byte[1024];
            int len;
            fileInputStream = new FileInputStream(file);
            fileOutputStream = new FileOutputStream(file2);
            while ((len = fileInputStream.read(buffer)) != -1) {
                fileOutputStream.write(buffer, 0, len);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (fileInputStream != null)
                    fileInputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                if (fileOutputStream != null)
                    fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
                
        
        版权归属:
        张宇顺
      
      
        
        本文链接:
        
          https://www.zhangyushun.com/archives/iofileinputstream-he-fileoutputstream-shi-xian-tu-pian-fu-zhi-
        
      
      
        
        许可协议:
        
        本文使用《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》协议授权
        
      
    
        
      
        
      
评论区