简单的问题。
dis.read()和dis.readUTF()有什么不同
例如,dis.read()只读到字节数组,dis.readUTF()访问String类型。
这是正确的吗?
如果服务器已经实现了dis.readUTF(),它不能读取字节流?
@Override
public void run() {
// TODO Auto-generated method stub
while(mEnabled)
{
if (!mFileReceive) {
try {
// read
String tmpStr = dis.readUTF();
// here come `dis.readUTF()` <- it is can not read byte array?
mStringBuffer += tmpStr;
if (tmpStr.length() >= 4096)
continue;
System.out.println("Print : " + mStringBuffer);
parse = new ParseJSON(null, mStringBuffer.toString());
// Ack Message
if (mAckEnabled) {
mFileName = "{opcode:0x06,ACK:C" + parse.getParsedData().get("ACK").substring(1) + "}";
dos.writeUTF(mFileName);
dos.flush();
System.out.println("Ack Message Send : " + mFileName);
mFileName = null;
}
if (parse.getParsedData().get("opcode").equals("155")) {
mFileReceive = true;
}
parse.clear();
parse = null;
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("ServerThread disconnect");
break;
}发布于 2012-06-05 13:44:18
readUTF()以以修改后的UTF-8格式编码的Unicode字符串的表示形式从流中读取数据;然后将该字符串作为字符串返回。
你应该使用以字节数组为参数的读取方法。下面是它的解释:
public final read(byte[] b)引发IOException
从包含的输入流中读取一定数量的字节,并将它们存储到缓冲区数组b中。实际读取的字节数以整数形式返回。
https://stackoverflow.com/questions/10891494
复制相似问题