Combining HTML files in Java

I want to merge several HTML files into one. For example, if I have two HTML files that print WELCOME and XYZ respectively, can I merge these two files into one that WELCOME XYZ can display together? I want to do these operations for several, suppose 1500 files.

Appreciate any help.

+4
source share
3 answers

You can use HTML parsing / manipulation API like JSoup .

+3
source

create one html file and continue to include several files using the command below ...

 <!--#include virtual="insertthisfile1.html" --> <!--#include virtual="insertthisfile2.html" --> <!--#include virtual="insertthisfile3.html" --> <!--#include virtual="insertthisfile4.html" --> 
+1
source

You can do this by iterating over all your files and adding the contents of the <body>...</body> together programmatically.

  • Get all html file names in ArrayList<String>
  • Create StringBuilder
  • Read each HTML file line by line until you find a line with the body tag
  • Reading from this tag begins until you find a line with the closing of the body tag
  • Add this content to StringBuilder
  • After all the files have been read, write the contents of StringBuilder to a single file.

At the end you will get one HTML file

-one
source

Source: https://habr.com/ru/post/1394750/


All Articles