0

I am trying to output an html file that used to be a .txt file. I had to format the .txt file into html using regex. I tried doing what user Krige did on here: Write HTML file using Java I'm still a beginner, how do I write the newly made .html file to the $body - and then display it?

File htmlTemplateFile = new File("path/template.html");
String htmlString = FileUtils.readFileToString(htmlTemplateFile);
String title = "New Page";
String file = "Shakespeare.html" 
htmlString = htmlString.replace("$body", file);
File newHtmlFile = new File("path/new.html");
FileUtils.writeStringToFile(newHtmlFile, htmlString);
Community
  • 1
  • 1
  • Writing to the file, see [Basic I/O](https://docs.oracle.com/javase/tutorial/essential/io/); for displaying [Integrating the Desktop class](https://docs.oracle.com/javase/tutorial/uiswing/misc/desktop.html) – MadProgrammer May 17 '15 at 21:30

1 Answers1

0

You can append the string to your document as it should appear in your html file.

BufferedWriter bw = new BufferedWriter(new FileWriter(file));
String title = "New Page";
String body = "<body><p>This is Body</p></body>";
bw.write("<html><head><title>");
bw.write(title);
bw.write("</title></head>");
bw.write(body);
bw.write("</title></head></html>");
bw.close();
Eranda
  • 1,439
  • 1
  • 17
  • 30