拆分二进制文件,将数据添加到每个块?

编程入门 行业动态 更新时间:2024-10-28 10:33:24
本文介绍了拆分二进制文件,将数据添加到每个块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我必须在其中我有一个二进制文件转换成一个自定义的文件格式,这就需要分割文件中添加一些数据,然后将其重新打包为新文件的项目工作。

I have to work on a project in which I have to convert a binary file into a custom file format, which requires splitting the file adding some data to it and then repacking it into the new file.

例如

我有1 MB的文件,我必须把它分割成固定长度的数据块,然后加入一些数据作为头吧。之后,整个文件将被重新包装成一个新的文件中。

I have a file of 1 MB and I have to split it into chunks of fixed length and then adding some data as a header to it. After that the entire file will be repackaged into a new file.

请任何帮助将AP preciated。

Please any help will be appreciated.

推荐答案

首先,你使用的 DataInputStream以读的X字节块为单个字节数组,其中x是块大小。我建议将这些字节数组存储在一个的ArrayList

First you use a DataInputStream to read chunks of x bytes into individual byte arrays, where x is your chunk size. I would suggest to store these byte arrays in an ArrayList.

然后创建一个 DataOutputStream类为创建新的文件。

Then you create a DataOutputStream for creating the new file.

最后,你遍历一个for循环的ArrayList和数组的内容写入DataOutputStream类,preceded或之后的附加数据,您需要添加对每个块。

Finally, you iterate over your ArrayList with a for loop and write the contents of the arrays to the DataOutputStream, preceded or followed by the additional data you need to add for each chunk.

我希望我能够帮助你。当事情不清,随意问。

I hope I was able to help you. When something is unclear, feel free to ask.

更多推荐

拆分二进制文件,将数据添加到每个块?

本文发布于:2023-11-03 07:58:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1554628.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:二进制文件   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!