iodemo3.java
来自「JAVA的一些基础教程」· Java 代码 · 共 42 行
JAVA
42 行
import java.io.*;
public class IODemo3{
public static void printArray(byte bytes[] )
{
System.out.println("数据长度:"+ bytes.length);
for(int i=0; i< bytes.length; i++)
{
System.out.print(Integer.toHexString(bytes[i])+ " ");
}
System.out.println();
for(int i=0; i< bytes.length; i++)
{
System.out.write(bytes[i]);
}
System.out.flush();
}
public static byte[] 读取指定长度的数据()
{
byte[] 数据 = null;
try {
数据 = new byte[30];
int 偏移 = 0;
while (偏移 <数据.length)
{
int 读取字节数 = System.in.read(数据, 偏移, 数据.length - 偏移);
System.out.println("读取的字节数:"+ 读取字节数);
if (读取字节数 == -1) break; //数据流结束
偏移 += 读取字节数;
}
}
catch (IOException e)
{
System.err.println("Couldn't read from System.in!");
}
return 数据;
}
public static void main(String[] args) throws Exception
{
printArray(读取指定长度的数据());
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?