如题,代码如下:
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!");
}
}
}请大家帮忙看一下,谢谢了.
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!");
}
}
}请大家帮忙看一下,谢谢了.
解决方案 »
- 请问dom4j输出xml时,怎么输出&?
- jdbc PreparedStatement 的 setString() 方法的问题
- 看看这个java基础面试题
- RMI编译时用rmic不能生成Skeleton(骨架类),不知道为什么,求高手指点
- 一个关于AWT的新手问题,请各位大侠指教!在线等待
- 我有个想法想问问大家帮忙想下行不行的通
- 请教:Java应用程序如何发布?那一堆class如何打包为可直接运行的EXE?初学Java,见笑的说
- 急,今天公司给我出的一个难题?
- jsp连接问题,帮帮忙
- csdn中的经典问答回顾,值得一看!!!
- 【新手提问】请问怎么弹出对话窗口,可以选择确定和取消?按确定继续,按取消退出.
- Unknown column 'xxxxx' in 'field list'
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();
}
跟踪到了这一行,
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();
}
就是跟踪到红色的这一行,就没有了下文了,问题应该是出在了这一行
看看是否能写,可以的话第二个代码可能没问题,而是getDealedFile();里的问题
楼主看看第二个写文件的while究竟循环了没有吧
"我晕!
楼主看看第二个写文件的while究竟循环了没有吧"
文件读到头了,没有了WHILE循环,谢谢大家.结贴了.