JDK1.4下HTTP请求后,无返回数据(但是我把代码放到JDK1.6的环境下就行),求大家帮忙看下,谢了~~~~
in = urlCon.getInputStream();
DataInputStream din = new DataInputStream(in);
byte [] btArr = new byte [1024];
int i = 0;
while ( true )
{
if ( i >= btArr.length )
{
byte [] temp = new byte [1024 + i];
System.arraycopy( btArr , 0 , temp , 0 , btArr.length ) ;
btArr = temp ;
}
try
{
btArr [i] = din.readByte();
}
catch ( Exception e )
{
break;
}
i++;
}
byte [] ctArr = new byte [ i ] ;
System.arraycopy( btArr , 0 , ctArr , 0 , ctArr.length ) ;
inMsg = new String( ctArr , "UTF-8" ) ;
System.out.println( inMsg ) ;
[解决办法]
测试类下jdk级别设置为1.4没有问题
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
File f = new File("E:\\test.txt");
InputStream in = null;
try {
in = new FileInputStream(f);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
DataInputStream din = new DataInputStream(in);
byte[] btArr = new byte[1024];
int i = 0;
while (true) {
if (i >= btArr.length) {
byte[] temp = new byte[1024 + i];
System.arraycopy(btArr, 0, temp, 0, btArr.length);
btArr = temp;
}
try {
btArr[i] = din.readByte();
} catch (Exception e) {
break;
}
i++;
}
byte[] ctArr = new byte[i];
System.arraycopy(btArr, 0, ctArr, 0, ctArr.length);
String inMsg;
try {
inMsg = new String(ctArr, "UTF-8");
System.out.println(inMsg);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
[解决办法]
我自己做了个测试也是没问题的,但是在调用别人接口时,JDK1.4就出问题了,JDK1.6就没问题。。。
[解决办法]
你调用别人的接口有问题,这说明别人提供的接口jdk级别比你的高。你用低版本的jdk去调用自然会报错,比如说泛型你的jdk1.4就不支持。高版本一般兼容低版本,所以你可以把你自己的jdk升级一下。
[解决办法]
那还是算了,我这是公司的项目,我不可能随便升级的,而且我还不能让接口方去改,坑爹。。。