iodemo9.java

来自「JAVA的一些基础教程」· Java 代码 · 共 38 行

JAVA
38
字号
import java.io.*;
public class IODemo9
	{
	public static void 读取数据(byte bytes[])
		{
		try{
			ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
			//读取8个字节,为一个长整数
			long a = 0;
			for(int i=0; i< 8; i++)
			a = (a << 8) | bis.read();
			System.out.println("读取了一个长整数值为:" + a + 
                          " 其十六进制值为 :" +Long.toHexString(a));

			int b = 0;
			for(int i=0; i< 4; i++)
			b = (b << 8) | bis.read();
			System.out.println("读取了一个整数值为:" + b + 
                              " 其十六进制值为 :" +Integer.toHexString(b));

			short  c = 0;
			for(int i=0; i< 2; i++)
			c = (short)((c << 8) | bis.read());
			System.out.println("读取了一个整数值为:" + c + " 其十六进制值为 :" 
					+Integer.toHexString(c));
				
		}catch(Exception  e){
		}
	}

	public static void main(String arg[])
	{
		byte 字节数组[] = {0X25,0X26,0X27,0X28,0X30,0x31,0x32,
				0x33,0x34,0x35,0x36,0X37,0X38,0X39};
		读取数据(字节数组);
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?