下面是我写的源码,每次在读取数据的时候在“开始循环”下面的for循环里面就出问题了;请问各位大侠我的代码有什么问题?
try {
// 1接收消息
serverInput = s.getInputStream();
//serverOutput = s.getOutputStream();
System.out.println("新系统收到的消息 --------start ------------------------------------ ");
int imLen = 2 + 2 + 2 + 8 + 2;
byte[] lenBuffer=new byte[imLen];
for(int i=0;i<imLen;i++)
{
lenBuffer[i]=(byte)serverInput.read();
}
String sss = new String(lenBuffer,"gb2312");
serverOutput.write(lenBuffer);
System.out.println(" 收到的消息 sss == " + sss);
int xmlLen = 4;
byte[] xmlBuffer=new byte[xmlLen];
for(int i=0;i<xmlLen;i++)
{
xmlBuffer[i]=(byte)serverInput.read();
}
String sss2 = new String(xmlBuffer,"iso8859-1");
int xmlFileLen = IntTools.byteToInt(xmlBuffer);
System.out.println(" 收到的消息 sss2 == " + xmlBuffer.length);
byte[] line= new byte[xmlFileLen];
System.out.println(" 开始循环 " );
for(int i=0;i<xmlFileLen;i++)
{
line[i]=(byte)serverInput.read();
}
System.out.println(" 结束循环 " );
String xmlFile = new String(line,"gb2312");
System.out.println(" 收到的xml文件内容 == " + xmlFile);
int iLen = 2;
byte[] ib=new byte[iLen];
System.out.println(" xml ");
for(int i=0;i<iLen;i++)
{
ib[i]=(byte)serverInput.read();
}
System.out.println(" xml ");
String sss3 = new String(ib,"gb2312");
System.out.println("ProcessSocket 收到的消息 sss3 == " + sss3);
System.out.println("新系统收到的消息 --------end ------------------------------------------------------------------ ");
这个还奇怪的很 我捕获异常了 但是没有异常的日志!
lenBuffer[i]=(byte)serverInput.read();
如果是这句出问题有可能是空指针错误本回答被提问者采纳