public static void copy(File file, File dest) throws FileNotFoundException {
if (!file.exists()) {
throw new FileNotFoundException(file.getName() + " not found");
}
if (file.isDirectory()) {
dest.mkdirs();
return;
}
if (!file.isFile()) {
return;
}
FileInputStream in = null;
FileOutputStream out = null;
try {
in = new FileInputStream(file);
out = new FileOutputStream(dest);
byte[] buffer = new byte[1024];
int count = 0;
while ((count = in.read(buffer)) != -1) {
if (!isCanceled)
out.write(buffer, 0, count);
else
break;
}
in.close();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (in != null) {
in.close();
}
if (out != null) {
out.flush();
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
复制文件
最新推荐文章于 2024-06-06 18:30:00 发布
