public static void fileCopy(String src, String dest) {
File file = new File(src);
if (!file.exists()) {
System.out.println(src + " Not Exists. ");
return;
}
File fileb = new File(dest);
if (file.isFile()) {
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fis = new FileInputStream(file);
fos = new FileOutputStream(fileb);
byte[] bb = new byte[(int) file.length()];
fis.read(bb);
fos.write(bb);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
fis.close();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} else if (file.isDirectory()) {
if (!fileb.exists()) {
fileb.mkdir();
}
String[] fileList;
fileList = file.list();
for (int i = 0; i < fileList.length; i++) {
fileCopy(src + File.separator + fileList[i], dest
+ file.separator + fileList[i]);
}
}
}
java目录拷贝
最新推荐文章于 2023-09-06 18:30:07 发布