java 上传txt文档成功之后,打开上传成功之后的txt文档是空的??
怪我咯
怪我咯 2017-04-18 10:55:12
0
2
620

上传的代码:

String filepath = filetxt.substring(12);
        //创建文件输出流  
        FileOutputStream fos=null;  
        try {  
                  //设置文件保存路径  
                  String savePath=request.getSession().getServletContext().getRealPath("/")+filepath;  
                  System.out.println(savePath);
                  logger.debug("文件保存完整路径:"+savePath);  
                  //创建文件  
                  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{  
            //关闭输出流  
            fos.close();  
        }
       
        out.flush();
        out.close();

保存路径:D:apache-tomcat-7.0.42webappssimfencewyp.txt
但是打开之后,wyp.txt是空的,这是为什么????

怪我咯
怪我咯

走同样的路,发现不同的人生

모든 응답(2)
Peter_Zhu

fileoutputstream에 데이터를 쓰지 않았습니다.

伊谢尔伦

fos.append()를 사용하여 콘텐츠를 작성하세요. 무엇을 작성하든 wyp.txt에 무언가가 포함되어 최종적으로 플러시됩니다.

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!