Java实现简单的文件复制

时间:2022-10-11 21:00:21
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 关