标题:response.getOutputStream();这样抛出文件流提供下载功能的,但下载不成功, ...
取消只看楼主
lmn163525
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2015-7-8
 问题点数:0 回复次数:0 
response.getOutputStream();这样抛出文件流提供下载功能的,但下载不成功,提示文件已损坏。求解决
java 用ftp从linux上下载文件,下载下来提示文件损坏
office 2007  系列的文件可以打开 如word excel ppt等
office 2003系列的文件打不开,提示文件损坏 如word excel ppt等
带图片的打不开 也是提示文件损坏
linux 上是weblogic 10
在本机下载下来都没问题
本机是win7+tomcat6  什么原因呢?
高手帮忙看看。
另外会报:org. IOException caught while copying.
at org.(Util.java:129)
    at org.(FTPClient.java:1452)
    at com.lbs.brick.sys.ServiceBase.downFileFromLinux(ServiceBase.java:905)
    at com.lbs.lrs.ls.apps.sys.fileupdate.bp.SourceBSImpl.downloadVedioFromLinux(SourceBSImpl.java:177)
下载程序代码:
public Boolean downFileFromLinux(String vedioName,String vedioPath,HttpServletResponse response) throws Exception{
        Boolean flg = false;
        //创建ftp客户端
        FTPClient ftpClient = new FTPClient();   
        try {
            if(null==vedioPath||"".equals(vedioPath)){
                throw new Exception("文件路径未空");
            }
            String hostname = IisUtil.ftpurl;//ftp访问路径
            int port = IisUtil.ftpport;//ftp访问端口
            String username = IisUtil.ftpusername;//用户名
            String password = IisUtil.ftppassword;  //密码   
           //链接ftp服务器
           ftpClient.connect(hostname, port);
           ftpClient.setControlEncoding("UTF-8");
            ftpClient.setDataTimeout(18000);
            ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
            ftpClient.setFileTransferMode(FTPClient.BINARY_FILE_TYPE);
            ftpClient.enterLocalPassiveMode();
            
           //登录ftp
           ftpClient.login(username, password);
           int  reply = ftpClient.getReplyCode();  
           //如果reply返回230就算成功了,如果返回530密码用户名错误或当前用户无权限下面有详细的解释。
           if (!FTPReply.isPositiveCompletion(reply)) {  
                    ftpClient.disconnect();
                    throw new Exception("ftp用户名或密码错误!");
           }  
           
           response.reset();
          // response.setContentType("multipart/form-data");
           response.setContentType("application/x-msdownload");
            response.setCharacterEncoding("UTF-8");
            response.setHeader("Content-Disposition", "attachment; filename="
                    + URLEncoder.encode(vedioName, "UTF-8"));
            
            OutputStream  out = response.getOutputStream();
            ftpClient.retrieveFile(new String(vedioPath.getBytes("UTF-8"),"iso-8859-1"), out);
            out.flush();
            out.close();
           ftpClient.logout();
           flg=true;                  
            
        } catch (SocketException e) {
            
           throw new Exception("ftp错误1:"+e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
          // throw new Exception("ftp错误2:"+e.getMessage());
        }finally
        {  
           if (ftpClient.isConnected())
               {  
                  try
                    {  
                      ftpClient.disconnect();  
                    } catch (IOException ioe)
                   {  
                      ioe.printStackTrace();
                   }  
             }
          }
        return flg;
        
    }
搜索更多相关主题的帖子: 下载文件 office linux excel 图片 
2015-07-08 10:42



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-455196-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.092930 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved