標籤:mkdir 點擊 ret exists com copy 路徑 點擊事件 cal
//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"));
擷取本地檔案(檔案夾)上傳,無點擊事件