How to merge binary files using Java?

。_饼干妹妹 提交于 2020-01-25 00:21:05

问题


I am downloading file parts using socket, saving them as .part1, .part2 etc.( However I am not sure if I should). I am trying to merge them in a .bin file. Can any of you recommend me a way to do that? Should I read them all as binary and then append it? I don't even know if that makes sense actually.


回答1:


Why don't you open the first part for input, and open an output streamof the form

out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(outFile)));

then read in your first part file as bytes, and use the writeByte() method to write it all out.

Then close the first part, open the second part, and read it in, then out to the output file.

Will that not merge the contents of the two files?




回答2:


I did it. Read files one by one and wrote them to output.



来源:https://stackoverflow.com/questions/4532462/how-to-merge-binary-files-using-java

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