我从数据库中取出数据来,写到xml文件中   ,通过ftp上传到某服务器,不知道咋回事,我本地的xml文件大小总是比上传上去的文件大,也就是会丢失一部分内容,这种情况是偶尔发生的,也就是说,有的时候是能上传成功的!!!!!!!!!!!我很郁闷阿,咋回事呢?5555555555555555555555

解决方案 »

  1.   

    用什么传的, 格式相同吗? 都是DOS ,或者都是UNIX?
      

  2.   

    格式应该无所谓
    还是ftp上传的类写的有问题吧
    应该是已上传文件大小<=要上传的文件大小的时候就继续传贴个代码看看清晰些
      

  3.   


    这是我的代码~~~~~嘿嘿!!
    private String SendFile(String pathName,String fileName)
        {
          FtpClient aftp;
          TelnetInputStream ins;
          TelnetOutputStream outs;
          DataOutputStream outputs;
          try
          {
              aftp = new FtpClient("123.22.12.218");
              aftp.login("1", "1");
              aftp.binary();
              aftp.cd("/");
              //showFileContents();
              if(aftp != null)
              {
                  int ch=1000;
                  RandomAccessFile sendFile = new RandomAccessFile(pathName, "r");
                  sendFile.seek(0L);
                  outs = aftp.put(fileName);
                  outputs = new DataOutputStream(outs);
                  for(; sendFile.getFilePointer() < sendFile.length(); outputs.write(ch))
                  {
                      ch = sendFile.read();
                      
                  }
                  outs.close();
                  sendFile.close();          }          return "yes";
          }catch(Exception ex)
          {
              return ex.toString();
          }
        }  
      

  4.   

    代码没看出有问题,不行就直接读字节吧 ftpClient.binary();
    File file = new File("src\\com\\example\\test\\TestFtp.java");
    System.out.println(file.getAbsolutePath());
    tos = ftpClient.put("testaaa.txt");
    InputStream is = new FileInputStream(file);
    int len1 = (int) file.length();
    int len2 = 0;
    int len3 = 0;
    byte[] b = new byte[1024];
    while (len2 < len1) {
    len3 = len1 - len2;
    if (len3 >= 1024) {
    is.read(b);
    tos.write(b);
    len3 = 1024;
    } else {
    is.read(b, 0, len3);
    tos.write(b, 0, len3);
    }
    len2 += len3;
    }
    is.close();
    tos.close();