Skip to main content

APIzation: Replication Package

[Q#36513149][A#36513173] How Can I Format A HTML Page I'm Outputting From Java?

https://stackoverflow.com/q/36513149

I am messing around with a small project this weekend, and part of it I want to take the results of my output that would normally go to my console and output them to an HTML file. Now both lines print out just fine. But they print out on one line, nearly run together, and just don't look appealing in the slightest. Is there anything I can do in Eclipse to format the html page before I print my values to it?

Answer

https://stackoverflow.com/a/36513173

You can do one of two things. The first is code the html formatting into your program to be written out. In other words, something like inserting between your print statments. The other thing you could do is write a formatted html page and read it from memory as a long string, and then only overwrite the things you want to, perhaps by searching for specific tags and editing the text between them. When you are done you can save the file back. If all you need is a little bit of simple formatting, the first method will be better. If the page you want is quite complex, the second is the way to go.

APIzation

System.out.println("<br />");
package com.stackoverflow.api;

public class Human36513173 {

  public static void htmlFormat() {
    System.out.println("<br />");
  }
}

package com.stackoverflow.api;

/**
 * How Can I Format A HTML Page I'm Outputting From Java?
 *
 * @author APIzator
 * @see <a href="https://stackoverflow.com/a/36513173">https://stackoverflow.com/a/36513173</a>
 */
public class APIzator36513173 {

  public static void formatHtml() throws Exception {
    System.out.println("<br />");
  }
}