如题,代码如下:
   public void streamInFrom(DataInputStream dis) throws IOException {
        // Read the length (32 bits)
        length_ = dis.readInt();        if (length_ > MAX_LEN) {
            throw new IOException("Invalid Request length " + length_);
        }        requestType_ = dis.readInt();
        dataMode_    = dis.readInt();
        dataLen_     = dis.readInt();        if (dataLen_ > 0) {
            if (USER == requestType_ || PASS == requestType_ || RETR == requestType_) {
                byte buf[] = new byte[dataLen_];
                int read = dis.read(buf, 0, dataLen_);
                if (read == -1) {
                    throw new IOException("read client's request data error!");
                }
                this.data_ = new String(buf, ServerConfig.getTransferEncoding());
            }
            else if (STOR == requestType_) {
                this.dataFile_ = this.getStorFile();    //方法是建立一个文件,返回文件名
                int read = 0;
                int transfered = 0;
                byte buf[] = new byte[DATA_BUF];
                FileOutputStream fos = null;                try {
                    fos = new FileOutputStream(this.dataFile_);
                    while (transfered < this.dataLen_ && (read = dis.read(buf, 0, DATA_BUF)) != -1) {
                        fos.write(buf, 0, read);
                        transfered += read;
                    }
                }
                finally {
                    transfered = 0;
                    fos.flush();
                    fos.close();
                    this.unzip();
                }                byte buf2[] = new byte[DATA_BUF];
                this.dealedFile_ = this.getDealedFile();       //方法是建立另一个文件,返回文件名
                FileOutputStream fs = null;                try {
                    fs = new FileOutputStream(this.dealedFile_);
                    while (transfered < this.dataLen_ && (read = dis.read(buf2, 0, DATA_BUF)) != -1) {
                        fs.write(buf2, 0, read);
                        transfered += read;
                    }
                }
                finally {
                    transfered = 0;
                    fs.close();
                    this.unzip();
                }            }
            else {
                throw new IOException("service does not support the request with data!");
            }
        }
    }请大家帮忙看一下,谢谢了.

解决方案 »

  1.   

    try { 
          fs   =   new   FileOutputStream(this.dealedFile_); 
         while   (transfered   <   this.dataLen_   &&   (read   =   dis.read(buf2,   0,   DATA_BUF))   !=   -1)   { 
                                                    fs.write(buf2,   0,   read); 
                                                    transfered   +=   read; 
                                            } 
                                    } 
                                    finally   { 
                                            transfered   =   0; 
                                            fs.close(); 
                                            this.unzip(); 
                                    } 
     跟踪到了这一行,
      

  2.   

    唯一不一样的就是第二个少一个fs.flush();
      

  3.   

    去掉fs.flush()是一样的效果,
      

  4.   

    >跟踪到了这一行你那是好几行啊,你把fs.flush();加上看看吧
      

  5.   

    我再重现一下,最初的程序我是没有加fs.flush()的,这是我后来加上去的
      

  6.   

    try   {   
                fs       =       new       FileOutputStream(this.dealedFile_);   
              while       (transfered       <       this.dataLen_       &&       (read       =       dis.read(buf2,       0,       DATA_BUF))       !=       -1)       {   
                                                                                                    fs.write(buf2,       0,       read);   
                                                                                                    transfered       +=       read;   
                                                                                    }   
                                                                    }   
                                                                    finally       {   
                                                                                    transfered       =       0;   
                                                                                    fs.close();   
                                                                                    this.unzip();   
                                                                    }   
    就是跟踪到红色的这一行,就没有了下文了,问题应该是出在了这一行
      

  7.   

    研究了一下,问题可能出在this.dealedFile_ = this.getDealedFile();  你可以试一下,写第二个文件时仍然用第一个取得文件的方法this.dataFile_ = this.getStorFile();    
    看看是否能写,可以的话第二个代码可能没问题,而是getDealedFile();里的问题      
                
      

  8.   

    dis.read 你已经读到头了,肯定就没有了啊.
      

  9.   

    我晕!
    楼主看看第二个写文件的while究竟循环了没有吧               
      

  10.   

    停在那一行,不往下走了吗???finally里面的代码设个断点能不能到达??
      

  11.   

    "dis.read   你已经读到头了,肯定就没有了啊."
    "我晕! 
    楼主看看第二个写文件的while究竟循环了没有吧"
    文件读到头了,没有了WHILE循环,谢谢大家.结贴了.