java copyFile

 

java copyFile

 

public static void copyFile(File oldFile,File newFile) throws IOException{
    FileInputStream fis = new FileInputStream(oldFile);
    FileOutputStream fos = new FileOutputStream(newFile);
    int index=0;
    byte[] bytes = new byte[1024];
    while((index=fis.read(bytes))!=-1) {
        fos.write(bytes, 0, index);
    }
    fos.flush();
    fos.close();
    fis.close();
}

 

 

 

 

##########################

posted @ 2022-12-02 17:47  西北逍遥  阅读(180)  评论(0编辑  收藏  举报