wy123123000 2017-09-19 08:50 采纳率: 0%
浏览 3138

ftp上传文件名为中文上传报错怎么解决,在线求解!!!!

报错:IOException caught while copying.

 public static boolean upload(FTPParameter para,File file)  
            throws IOException {  

        boolean success = false;
        FTPClient ftp = new FTPClient();
        try {
            int reply;
            ftp.connect(para.hostName, para.port);//连接FTP服务器
            //如果采用默认端口,可以使用ftp.connect(url)的方式直接连接FTP服务器
            ftp.login(para.userName, para.passWord);//登录
            ftp.setControlEncoding("GBK");
            FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_NT);
            conf.setServerLanguageCode("zh");
            reply = ftp.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftp.disconnect();
                return success;
            }
            if(file.isDirectory()){           
                ftp.changeWorkingDirectory(para.uploadPath);  
                String[] files = file.list();             
                for (int i = 0; i < files.length; i++) {      
                    File file1 = new File(file.getPath()+"\\"+files[i] );      
                    if(file1.isDirectory()){      
                        upload(para,file1);      
                        ftp.changeToParentDirectory();      
                    }else{                    
                        File file2 = new File(file.getPath()+"\\"+files[i]);      
                        FileInputStream input = new FileInputStream(file2);
                        ftp.storeFile(file2.getName(), input);      
                        input.close();                            
                    }                 
                }      
            }else{      
                File file2 = new File(file.getPath());      
                FileInputStream input = new FileInputStream(file2);      
                ftp.storeFile(file2.getName(), input);      
                input.close();        
            }      

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (ftp.isConnected()) {
                try {
                    ftp.disconnect();
                } catch (IOException ioe) {
                }
            }
        }
        return success;  
    }  

  • 写回答

4条回答 默认 最新

  • Oh_my_godness 2017-09-19 09:01
    关注

    gbk不行就改成utf-8再试试看

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题