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

java一个文件里是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());
}
}
数组下标越界了吧?

你的i<=b.length应该改成i<b.length

Copyright © 2007-2012 www.chuibin.com 六维论文网 版权所有