File读取 复制

package ldz;

import java.io.*;
import java.util.*;

public class FileTest {

    public static void main(String[] args) {
        FileInputStream in;
        FileOutputStream out;
        try {
//          in =new FileInputStream("src/test_in.txt");//文本
//          out=new FileOutputStream("src/test_out.txt");
            in =new FileInputStream("src/1.png");// D:\\python练习\\FileTest\\src\\1.PNG
            out=new FileOutputStream("src/2.png");
            byte[] b=new byte[1024*8];
            int len=0;
            while((len = in.read(b))!=-1){
                out.write(b);
                out.flush();
            }
            out.close();
            in.close();
        } catch (IOException e) {
            
            e.printStackTrace();
        }

        
    }

}

你可能感兴趣的:(File读取 复制)