Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
330 views
in Technique[技术] by (71.8m points)

java 上传txt文档成功之后,打开上传成功之后的txt文档是空的??

上传的代码:

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是空的,这是为什么????


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

你没有往fileoutputstream写数据。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...