Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating Output in JAVA

Tags:

java

html

Can we generate an .html doc using java? Usually we get ouput in cmd prompt wen we run java programs. I want to generate output in the form of .html or .doc format is their a way to do it in java?

like image 437
harshini Avatar asked Dec 02 '22 02:12

harshini


1 Answers

For HTML

Just write data into .html file (they are simply text files with .html extension), using raw file io operation

For Example :

    StringBuilder sb = new StringBuilder();
    sb.append("<html>");
    sb.append("<head>");
    sb.append("<title>Title Of the page");
    sb.append("</title>");
    sb.append("</head>");
    sb.append("<body> <b>Hello World</b>");
    sb.append("</body>");
    sb.append("</html>");
    FileWriter fstream = new FileWriter("MyHtml.html");
    BufferedWriter out = new BufferedWriter(fstream);
    out.write(sb.toString());
    out.close();

For word document

This thread answers it

like image 177
jmj Avatar answered Dec 05 '22 09:12

jmj