Java 类似于二进制数据的扫描仪

Java 类似于二进制数据的扫描仪,java,Java,有类似于二进制数据扫描仪的东西吗?例如,我希望在每次调用某个方法时使用类似“\r\n”的分隔符并获取byte[]。你能为我提供能创造奇迹的课程吗?雅加达公共图书馆有一个你可以使用的图书馆。只需从下载.jar并下载它们的.jar,然后通过addexternaljar将其添加到构建路径中IOUtils.toByteArray(InputStream输入)您可以使用以下类: 希望这有助于考虑使用和: 读起来就像: File file = new File("binaryFile.dat"); File

有类似于二进制数据扫描仪的东西吗?例如,我希望在每次调用某个方法时使用类似“\r\n”的分隔符并获取byte[]。你能为我提供能创造奇迹的课程吗?

雅加达公共图书馆有一个你可以使用的图书馆。只需从下载.jar并下载它们的.jar,然后通过addexternaljar将其添加到构建路径中
IOUtils.toByteArray(InputStream输入)

您可以使用以下类:

希望这有助于考虑使用和:

读起来就像:

File file = new File("binaryFile.dat");
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
DataInputStream dis = new DataInputStream(bis);

byte[] array1 = new byte[dis.readInt()];
for(int i = 0; i < array1.length; i++) array1[i] = dis.readByte();

byte[] array2 = new byte[dis.readInt()];
for(int i = 0; i < array2.length; i++) array2[i] = dis.readByte();

byte[] array3 = new byte[dis.readInt()];
for(int i = 0; i < array3.length; i++) array3[i] = dis.readByte();
File File=new文件(“binaryFile.dat”);
FileInputStream fis=新的FileInputStream(文件);
BufferedInputStream bis=新的BufferedInputStream(fis);
DataInputStream dis=新的DataInputStream(bis);
字节[]数组1=新字节[dis.readInt()];
对于(inti=0;i
但我想得到例如整行字节。
File file = new File("binaryFile.dat");
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos);
DataOutputStream dos = new DataOutputStream(bos);

byte[] array1 = ...
byte[] array2 = ...
byte[] array3 = ...

dos.writeInt(array1.length);
for(byte b : array1) dos.wrtieByte(b);

dos.writeInt(array2.length);
for(byte b : array2) dos.wrtieByte(b);

dos.writeInt(array3.length);
for(byte b : array3) dos.wrtieByte(b);
File file = new File("binaryFile.dat");
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
DataInputStream dis = new DataInputStream(bis);

byte[] array1 = new byte[dis.readInt()];
for(int i = 0; i < array1.length; i++) array1[i] = dis.readByte();

byte[] array2 = new byte[dis.readInt()];
for(int i = 0; i < array2.length; i++) array2[i] = dis.readByte();

byte[] array3 = new byte[dis.readInt()];
for(int i = 0; i < array3.length; i++) array3[i] = dis.readByte();