擷取本地檔案(檔案夾)上傳,無點擊事件

來源:互聯網
上載者:User

標籤: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"));  

 

擷取本地檔案(檔案夾)上傳,無點擊事件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.