/**
* 拷贝文件,文件存在可以从后面追加文件数据,可用于文件操作失败续存操作
*
* @param fileDir
* 被拷贝文件位置
* @param copyFileDir
* 拷贝到的目标文件
* @param xuchuan
* 文件存在是否从文件后面添加
* @throws IOException
*/
public static void copyFile(String fileDir, String copyFileDir, boolean xuchuan) throws IOException {
// 原始文件
File fIn = new File(fileDir);
RandomAccessFile in = new RandomAccessFile(fIn, "r");// 以只读写入方式打开
// 拷贝文件
File fOut = new File(copyFileDir);
RandomAccessFile randomFile = new RandomAccessFile(fOut, "rw");// 以读写入方式打开
// 一次读多个字节
if (fOut.exists() && xuchuan) {
long fileLong = 0;
fileLong = fOut.length();
// 读取移动指针到指定位置
in.seek(fileLong);
// 写入移动指针到指定位置
randomFile.seek(fileLong);
}
// 一次读多个字节
byte[] tempbytes = new byte[1024];
int byteread = 0;
while ((byteread = in.read(tempbytes)) != -1) {
// 写文件
randomFile.write(tempbytes, 0, byteread);
}
randomFile.close();
in.close();
}