//url,realPath必填参数 1 public String updatebendi()throws Exception{ 2 ServletContext servletContext = ServletActionContext.getServletContext(); 3 //获取项目根目录路径 4 //String realPath= servletContext.getRealPath("/")+"image/yyy/yuangong"; 5 String realPath= "D:/image/yyy/yuangong"; 6 System.out.println("路径::::"+realPath); 7 System.out.println("file:::"+file); 8 File mulu=new File(realPath); 9 if(!mulu.exists()){ 10 mulu.mkdir(); 11 } 12 String url="D:/logs"; 13 //获取url的文件或文件夹 14 File file2 = new File(url); 15 File local=new File(mulu,file2.getName()); 16 System.out.println("名字::::"+file2.getName()); 17 18 //将file2文件拷贝到local文件 //File local = new File(mulu,fileFileName); 19 //FileUtils.copyFile(file2, local); 20 21 //将file2文件夹拷贝到local文件夹 22 FileUtils.copyDirectory(file2, local); 23 return SUCCESS; 24 }
2.copy几类用法
1 //结果是cxyapi和cxyapi1在同一目录 2 FileUtils.copyDirectory(new File("D:/cxyapi"), new File("D:/cxyapi1")); 3 //结果是将cxyapi拷贝到cxyapi2下 4 FileUtils.copyDirectoryToDirectory(new File("D:/cxyapi"), new File("D:/cxyapi2")); 5 6 //拷贝文件 7 FileUtils.copyFile(new File("d:/cxyapi.xml"), new File("d:/cxyapi.xml.bak")); 8 //拷贝文件到目录中 9 FileUtils.copyFileToDirectory(new File("d:/cxyapi.xml"), new File("d:/cxyapi")); 10 //拷贝url到文件 11 FileUtils.copyURLToFile(new URL("http://www.cxyapi.com/rss/cxyapi.xml"), new File("d:/cxyapi.xml"));
时间: 2024-11-05 16:06:52