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

上传的代码:

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才会有东西,最后flush一下

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!