日期:2014-05-20 浏览次数:21028 次
public class Test {
private static byte w[] = new byte[1024];
public void readInt() throws IOException{//按照int来读取
System.out.print("Integer info:\t");
FileInputStream fileInS = new FileInputStream("F:/test.txt");//文件中是“你好”
int w = fileInS.read() ;
while( -1 != w ){
System.out.print(w+" ");
w = fileInS.read();
}
System.out.println();
}
public void readByteArray() throws IOException{
System.out.print("ByteArray info: \t");
FileInputStream fileInS = new FileInputStream("F:/test.txt");//文件中是“你好”
while( -1 != fileInS.read(w) ){
String tmp = toHexDecimal(w);
System.out.print(tmp);
}
System.out.println();
}
private String toHexDecimal(byte... decimal){//将byte[]转型为16进制
byte[] refDecimal = decimal;
StringBuffer sBuf = new StringBuffer();
for( int i=0; i<refDecimal.length ; i++ ){
sBuf.append(Integer.toHexString(refDecimal[i])).append(" ");
}
return sBuf.toString() ;
}
Integer info: 228 189 160 229 165 189
ByteArray info: ffffffe4 ffffffbd ffffffa0 ffffffe5 ffffffa5