⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iodemo10.java

📁 JAVA的一些基础教程
💻 JAVA
字号:
import java.io.*;

public class IODemo10
	{
	public static void 理解1(byte 源数据[]) throws Exception
	{
		ByteArrayInputStream bis = new ByteArrayInputStream(源数据);
		DataInputStream dis = new DataInputStream(bis);
		long a= dis.readLong();	//八个字节
		short b = dis.readShort();	//两个字节
		byte c = dis.readByte();	//一个字节
		System.out.println("理解为一个长整数值为:" + a + " 其十六进制值为 :" +Long.toHexString(a));
		System.out.println("和一个短整数值为:" + b + " 其十六进制值为 :" +Integer.toHexString(b));
		System.out.println("和一个单字节整数值为:" + c + " 其十六进制值为 :" +Integer.toHexString(c));
		System.out.println();
	}

	public static void 理解2(byte 源数据[]) throws Exception
	{
		DataInputStream dis = new DataInputStream(new ByteArrayInputStream(源数据));
		double a = dis.readDouble();	//八个字节
		byte b = dis.readByte();
		short c = dis.readShort();
		System.out.println("理解为一个双精度小数值为:" + a + " 其十六进制值为 :"
			 +Long.toHexString(Double.doubleToLongBits(a)));
		System.out.println("和一个单字节整数:"+ b + " 其十六进制的值为:"
		 + Integer.toHexString(b));
		System.out.println("和一个双节值为:" + c + " 其十六进制值为 :"
		 +Integer.toHexString(c));
		System.out.println();
	}

	public static void 理解3(byte 源数据[]) throws Exception
	{
		DataInputStream dis =new DataInputStream( new ByteArrayInputStream(源数据));
		String a = dis.readUTF();
		System.out.print("理解为一个字符窜为:");
		System.out.print(a);
	}
	public static void main(String arg[]) throws Exception
	{
		byte 源数据[] = {0x0,0xa,(byte)0xE4,(byte)0xBB,(byte)0xB7,(byte)0xE9,
		(byte)0x92,(byte)0xB1,0x31,0x2E,0x30,0x30};
		System.out.println("源数据为:");
		for(int i=0; i< 源数据.length; i++)
		 System.out.print(Integer.toHexString(源数据[i] & 0xFF));

		System.out.println("\n\n三种不同的理解为:\n");		
		理解1(源数据);
		理解2(源数据);
		理解3(源数据);
	}
}

⌨️ 快捷键说明

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