Java复制文件工具类
发布时间:2020-12-15 03:18:48 所属栏目:Java 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.I
以下代码由PHP站长网 52php.cn收集自互联网 现在PHP站长网小编把它分享给大家,仅供参考 import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; public class FileUtils { public FileUtils() { // TODO Auto-generated constructor stub } /** * @warning The name of file must be end with .xls * @param res The resource file * @param des The destination * @return * @throws FileNotFoundException */ public static boolean toCopy(String res,String des){ boolean flag=false; Boolean bool1 = res.endsWith(".xxx"); Boolean bool2 = des.endsWith(".xxxb"); if(!bool1 && !bool2){ return false; } //输入源文件 File file = new File(res) ; FileInputStream fr=null; //复制目标文件 File desFile = new File(des); FileOutputStream bw=null; try { fr = new FileInputStream(file); bw = new FileOutputStream(desFile); //buffer byte[] b = new byte[512]; while(fr.read(b)!=-1){ bw.write(b); } bw.flush(); flag=true; } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); }catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ if(fr != null) try { fr.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if(bw != null){ try { bw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return flag; } } 把.xxx格式的文件复制到指定路径。 以上内容由PHP站长网【52php.cn】收集整理供大家参考研究 如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |