如题,代码如下:
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!");
}
}
}请大家帮忙看一下,谢谢了.
解决方案 »
- 文件复制异常java.nio.channels.ClosedChannelException
- 求助文件内容的读取
- Java Web Start 和 axis2
- [高分求解]Graphics问题,在鼠标drag的画线太闪了,请高人指点指点~ [有代码]
- 书上的有个例子居然不能运行,晕~~~
- 关于用ListIterator遍历,修改,删除ArrayList的同步问题
- java构造函数的用法及意义?
- 关于Java的几个问题!
- oracle中存取clob字段显示乱码
- 我想在调JTable的列宽时,产生一个事件,我该加什么侦听?
- 【新手提问】请问怎么弹出对话窗口,可以选择确定和取消?按确定继续,按取消退出.
- 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循环,谢谢大家.结贴了.