/**
* 复制文件。targetFile为目标文件,file为源文件
*
* @param targetFile
* @param file
*/
public static void copyFile(File targetFile, File file) {
if (targetFile.exists()) {
System.out.println("文件" + targetFile.getAbsolutePath()
+ "已经存在,跳过该文件!");
return;
} else {
createFile(targetFile, true);
}
InputStream is = null;
FileOutputStream fos = null;
System.out.println("复制文件" + file.getName() + "到"
+ targetFile.getAbsolutePath());
try {
is = new FileInputStream(file);
fos = new FileOutputStream(targetFile);
byte[] buffer = new byte[1024];
int length = 0;
while ((length = is.read(buffer)) != -1) {
fos.write(buffer, 0, length);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(fos);
}
}
* 复制文件。targetFile为目标文件,file为源文件
*
* @param targetFile
* @param file
*/
public static void copyFile(File targetFile, File file) {
if (targetFile.exists()) {
System.out.println("文件" + targetFile.getAbsolutePath()
+ "已经存在,跳过该文件!");
return;
} else {
createFile(targetFile, true);
}
InputStream is = null;
FileOutputStream fos = null;
System.out.println("复制文件" + file.getName() + "到"
+ targetFile.getAbsolutePath());
try {
is = new FileInputStream(file);
fos = new FileOutputStream(targetFile);
byte[] buffer = new byte[1024];
int length = 0;
while ((length = is.read(buffer)) != -1) {
fos.write(buffer, 0, length);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(fos);
}
}