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 ) ;

解决方案 »

  1.   

    测试类下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();
    }

    }
      

  2.   

    我自己做了个测试也是没问题的,但是在调用别人接口时,JDK1.4就出问题了,JDK1.6就没问题
      

  3.   

    你调用别人的接口有问题,这说明别人提供的接口jdk级别比你的高。你用低版本的jdk去调用自然会报错,比如说泛型你的jdk1.4就不支持。高版本一般兼容低版本,所以你可以把你自己的jdk升级一下。