精品久久免费视频,国产在线99,欧美伊人久久综合网,99欧美在线,久久伊人成人网,青青国产成人久久激情91麻豆,h黄视频在线观看

Struts2基本讀寫(xiě)法上傳文件 -電腦資料

電腦資料 時(shí)間:2019-01-01 我要投稿
【www.cfdfis.com - 電腦資料】

   

String savepath = ServletActionContext.getServletContext().getRealPath("/upload");System.out.println(savepath);    try {    File desc = new File(savepath,picFileName);    //FileUtils.copyFile(pic, desc);  《--采用此種方法以下均可省略,較簡(jiǎn)單    InputStream is = new FileInputStream(pic);    OutputStream s = new FileOutputStream(desc);    byte[] buf = new byte[1024];    int len;    while((len=is.read(buf))!=-1){        os.write(buf);    }    is.close();    os.close();    } catch (Exception e) {        e.printStackTrace();    }

    易錯(cuò)點(diǎn):若寫(xiě)成--》is.read(buf)<0 將無(wú)法讀取過(guò)來(lái), 但是會(huì)在目標(biāo)路徑生成一個(gè)零字節(jié)文件!

最新文章