How to merge >1000 xml files into one using Java

后端 未结 6 1785
予麋鹿
予麋鹿 2021-02-06 06:36

I am trying to merge many xml files into one. I have successfully done that in DOM, but this solution is limited to a few files. When I run it on multiple files >1000 I am getti

6条回答
  •  臣服心动
    2021-02-06 06:57

    For this kind of work I will suggest not to use DOM, reading the file content and making a substring is simpler and enough.

    I'm thinking of something like that :

    String rootContent = document.substring(document.indexOf(""), document.lastIndexOf("")+7);
    

    Then to avoid to much memory consummation. Write in the main file after every xml extraction with a BufferedWritter for example. For better performance you can also use java.nio.

提交回复
热议问题