Splitting Binary files and adding data to each chunk?

梦想与她 提交于 2019-12-12 01:25:51

问题


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.

For Example

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.

Please any help will be appreciated.


回答1:


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.

Then you create a DataOutputStream for creating the new file.

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.



来源:https://stackoverflow.com/questions/12296295/splitting-binary-files-and-adding-data-to-each-chunk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!