有什么像扫描仪的二进制数据?我希望例如使用分隔符,如“\ r \ n”,并在每次调用某个方法时都获取byte []。你能给我提供可以创造奇迹的课吗?类似扫描仪的二进制数据
2
A
回答
0
雅加达公共有一个图书馆,你可以使用。只需从jakarta下载.jar并下载它们的.jar,然后通过添加外部jar将其添加到您的构建路径中。 IOUtils.toByteArray(InputStream input)
0
可以使用java.io.InputStream类:
InputStream is = new FileInputStream("your_file");
byte[] b = new byte[is.available()]; //reads how much bytes are readable from file
is.read(b);//reads the file and save all read bytes into b
希望这有助于
1
考虑使用DataInputStream
和DataOutputStream
:
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();
相关问题
- 1. PHP类扫描仪
- 2. 扫描仪类 - hasNextDouble()
- 3. 扫描仪类Java
- 4. 扫描仪内的扫描仪错误
- 5. 进度条类似条码扫描仪照片拍摄图像
- 6. 为什么关闭扫描仪似乎破坏了新的扫描仪?
- 7. 控制台扫描仪?
- 8. 扫描antlr3中的二进制文件
- 9. 扫描仪类帮助
- 10. 抽象类与扫描仪
- 11. 扫描仪类方法
- 12. 扫描仪,useDelimiter
- 13. 由扫描仪
- 14. 与扫描仪
- 15. ArrayList的扫描仪
- 16. 扫描仪不扫描我的输入
- 17. 从扫描仪只读数
- 18. Java - 使用扫描仪以十六进制数字读取
- 19. 如何扫描声纳扫描仪
- 20. 扫描仪和StringTokenizer
- 21. 扫描仪开始
- 22. 春扫描仪豆
- 23. 循环扫描仪
- 24. Java扫描仪Lookahead
- 25. 带扫描仪的平均分类
- 26. 使用扫描仪类的问题
- 27. 与扫描仪类的异常
- 28. 使用扫描仪类的输入
- 29. 隐藏扫描仪进度条窗口
- 30. 如何改进HBase扫描仪?
但我想要例如整行字节。 – oneat 2013-03-05 18:33:22