2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > 超实用文件复制 移动 删除

超实用文件复制 移动 删除

时间:2021-02-16 17:22:54

相关推荐

超实用文件复制 移动 删除

文件复制

文件复制: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;}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。