这里是我试图通过mac上的终端在web浏览器中显示的文件。 当我运行该程序时,它不会将程序发送到Web浏览器,但它只是打印整个代码。 如果我的理解错误,请让我知道。 下面的代码应该给我一个输出为HTML文件:通过终端将您的输出重定向为html文件
你好
嗨,你好吗?
代码:
public class OutputHTML {
public static void main(String[] args) {
// DOCTYPE declaration
System.out.println(""-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
// html start
System.out.println("");
// head start
System.out.println("
");System.out.println();
// meta tag for encoding
System.out.println(" ");
System.out.println();
// title
System.out.println("
" + "Hello" + "");System.out.println();
// head end
System.out.println("");
// body start
System.out.println("
");System.out.println();
// heading
System.out.println("
" + "Hello" + "
");System.out.println();
// simple paragraph
System.out.println("
" + "Hi, how are you?" + "
");System.out.println();
// body end
System.out.println("");
// html end
System.out.println("");
}
}
+0
'(java OutputHTML> output.html && open output.html)'from terminal –
2011-04-15 20:31:37
+0
严重:1.打开FileOutputStream,在该流上创建一个printwriter,使用它来代替stdout。 2.使用java.awt.Desktop启动默认浏览器。 –
2011-04-15 20:37:12