解决方案 »

  1.   

    我这段代码的问题是卡死在:
     if (!ftpClient.completePendingCommand()) {
                            copyFalg = false;
                            return copyFalg;
                        }
    用标准的文件传输方式,放在缓存里谩慢的读是什么意思?能否讲的更清楚一些?谢谢
      

  2.   


      FileInputStream fis = null;
            FileOutputStream fos = null;
            byte[] buffer = new byte[100];
            int temp = 0;
            try{
                fis = new FileInputStream("a");
                fos = new FileOutputStream("b");
                while(true){
                    temp = fis.read(buffer,0,buffer.length);
                    if(temp == -1){
                        break;
                    }
                    fos.write(buffer,0,temp);
                }        
            }
            catch(Exception e){
                System.out.println(e);
            }
            finally{
                try{
                    fis.close();
                    fos.close();
                }
                catch(Exception e2){
                    System.out.println(e2);
                }
            }
      

  3.   

    这段代码只是基本的本地文件复制。
    我上面的代码是,通过FTP连接到FTP服务器进行远程文件的复制。
    和你说的不相同。inputStream = ftpClient.retrieveFileStream(from + PATH_SLASH + category);
                        // 复制文件时掉用了retrieveFileStream方法
                        // 调用完之后必须调用completePendingCommand释放,否则FTP会断开连接
                        if (!ftpClient.completePendingCommand()) {
                            copyFalg = false;
                            return copyFalg;
                        }
                        // 如果读取的文件流不为空则复制文件
                        if (inputStream != null) {
                            copyFalg = ftpClient.storeFile(to + PATH_SLASH + category, inputStream);
                            // 关闭文件流
                            inputStream.close();
                            if (!copyFalg) {
                                return copyFalg;
                            }
                        }
    这段代码就是在读取远程的某个文件,然后复制到新的地方。我也做了修改,
               inputStream = ftp.retrieveFileStream(fromFilePath);
                ftp.setDataTimeout(10000000);
                if (!ftp.completePendingCommand()) {
                    success = false;
                    return success;
                }
                outputStream = ftp.storeFileStream(toFilePath);            byte[] buf = new byte[1024 * 16];
                int size = 0;
                while ((size = inputStream.read(buf)) != -1){
                    outputStream.write(buf, 0, size);
                }但是还是出现 超过100KB的文件就复制不成功,小于100KB的文件就能偶复制成功。
      

  4.   

    你要先关闭流  inputStream.close();,然后再执行ftp.completePendingCommand,否则会出现问题
      

  5.   

    楼主,我也遇到了一样的问题,我最终解决方案是这样,将文件读到内存中去操作..不多说上代码,16Mb文件copy成功.
                                   client.setBufferSize(1024); 
    ByteArrayOutputStream fos=new ByteArrayOutputStream();
    client.retrieveFile(path+name, fos);
    ByteArrayInputStream in=new ByteArrayInputStream(fos.toByteArray());
    client.storeFile(path+newfilename, in);
    fos.close();
    in.close();