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();
}
}
------解决方案--------------------