文件复制
:
文件复制:public static boolean copyFile(File srcFile,File flFile){if (!srcFile.exists() || srcFile.isDirectory()) {return false;}if (!flFile.exists()) {flFile.mkdirs();}String fileName = srcFile.getName();//文件名称保持一致File newFile = new File(flFile,fileName);try {FileChannel fileIn = new FileInputStream(srcFile).getChannel();FileChannel fileOut = new FileOutputStream(newFile).getChannel();fileIn.transferTo(0, fileIn.size(), fileOut);fileIn.close();fileOut.close();} catch (IOException e) {return false;}return true;}
文件移动
:
public static boolean moveFile(File srcFile, File flFile) {if (!srcFile.exists() || srcFile.isDirectory()) {return false;}if (!flFile.exists()) {flFile.mkdirs();}String oldFileName = srcFile.getName();File dstFile = new File(flFile, oldFileName);if (srcFile.renameTo(dstFile)) {// 直接重命名绝对路径速度更快return true;} else{return false;}}
文件删除
:
public static boolean delete(File src) {if (!src.exists()) {return false;}if (src.isFile()) {src.delete();return true;} else{return false;}}