Java实现简单的文件复制

public class FileCopy {
    public static void main(String[] args) {
        String path = "d:\1.txt";
        String newPath = "d:\2.txt";
        try {
            InputStream is = new FileInputStream(path);
            OutputStream os = new FileOutputStream(newPath);
            int len = 0;
            byte[] b = new byte[1024];
            while((len = is.read(b)) != -1)
                os.write(b,0,len);
            os.close();
            is.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

 入出len byte while 关

原文地址:https://www.cnblogs.com/lxcmyf/p/6547108.html