文件的拷贝:
public static void copyFile(File file, File newFile) throws IOException {
if (!file.exists()) {
throw new IllegalArgumentException("文件:" + file + "不存在");
}
if (!file.isFile()) {
throw new IllegalArgumentException("文件:" + file + "不是文件");
}
FileOutputStream fos = new FileOutputStream(newFile);
FileInputStream fis = new FileInputStream(file);
byte[] buf = new byte[8 * 1024];
int b;
while ((b = fis.read(buf, 0, buf.length)) != -1) {
fos.write(buf, 0, b);
fos.flush();
}
fis.close();
fos.close();
}
public static void copyFile(File file, File newFile) throws IOException {
if (!file.exists()) {
throw new IllegalArgumentException("文件:" + file + "不存在");
}
if (!file.isFile()) {
throw new IllegalArgumentException("文件:" + file + "不是文件");
}
FileOutputStream fos = new FileOutputStream(newFile);
FileInputStream fis = new FileInputStream(file);
byte[] buf = new byte[8 * 1024];
int b;
while ((b = fis.read(buf, 0, buf.length)) != -1) {
fos.write(buf, 0, b);
fos.flush();
}
fis.close();
fos.close();
}