成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

java 上傳txt文檔成功之后,打開(kāi)上傳成功之后的txt文檔是空的??

瀏覽:147日期:2023-12-29 11:22:42

問(wèn)題描述

上傳的代碼:

String filepath = filetxt.substring(12);//創(chuàng)建文件輸出流 FileOutputStream fos=null; try { //設(shè)置文件保存路徑 String savePath=request.getSession().getServletContext().getRealPath('/')+filepath; System.out.println(savePath); logger.debug('文件保存完整路徑:'+savePath); //創(chuàng)建文件 File saveFile=new File(savePath); if(!saveFile.exists()){//判斷文件是否存在 saveFile.createNewFile(); } fos=new FileOutputStream(saveFile); logger.debug('fieldName:'+filepath+',with filename='+filepath); } catch (Exception e) { logger.error('Exception:',e); e.printStackTrace(); }finally{ //關(guān)閉輸出流 fos.close(); } out.flush();out.close();

保存路徑:D:apache-tomcat-7.0.42webappssimfencewyp.txt但是打開(kāi)之后,wyp.txt是空的,這是為什么????

問(wèn)題解答

回答1:

你沒(méi)有往fileoutputstream寫(xiě)數(shù)據(jù)。

回答2:

用fos.append()寫(xiě)入內(nèi)容,寫(xiě)什么,你的wyp.txt才會(huì)有東西,最后flush一下

標(biāo)簽: java