首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

一个资料里是16进制拿出来指定的数也可以说是字符错哪里了

2013-07-09 
一个文件里是16进制拿出来指定的数也可以说是字符错哪里了import java.io.FileInputStreamimport java.io

一个文件里是16进制拿出来指定的数也可以说是字符错哪里了
import java.io.FileInputStream;
import java.io.IOException;


public class getthatbyte {
static byte[]b = new byte[1024];
public static byte[] rFile(byte[]b){
try {
FileInputStream input = new FileInputStream("c:test.fsv");
input.read(b, 4, 4);
} catch (IOException e) {
e.printStackTrace();
}
return b;
}

public static  void main(String[] args)
{
getthatbyte.rFile(b);
String hex = new String();
for(int i=0;i<=b.length;i++)
{
hex = Integer.toHexString(b[i]&0XFF);
if(hex.length()==1)
{
hex = hex+'0';
}
}
System.out.println(hex.toUpperCase());
}
}

[解决办法]
数组下标越界了吧?
[解决办法]

引用:
00
00
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1024
at getthatbyte.printhexstring(getthatbyte.java:22)
at getthatbyte.main(getthatbyte.java:34)
改了下 我只要四个字节 打印出来这样的 再想想 


你这不就是数组下标越界嘛,你的i<=b.length应该改成i<b.length

热点排行