(JAVA)如何在浏览器中打开临时htm文件?

时间:2010-07-16 15:43:33

标签: java file browser temp

我试过了,但没有成功:

         File temp = File.createTempFile("document", ".htm");

         BufferedWriter out = new BufferedWriter(new FileWriter(temp));
         out.write("hi !!!"); 
         out.close();

         System.out.println(temp.toURI().toString());


         java.awt.Desktop.getDesktop().browse(temp.toURI());

1 个答案:

答案 0 :(得分:2)

以略微修改的形式为我工作:

    File temp;
    try {
        temp = File.createTempFile("document", ".htm");
        BufferedWriter out = new BufferedWriter(new FileWriter(temp));
        out.write("hi !!!");
        out.close();

        System.out.println(temp.toURI().toString());

        java.awt.Desktop.getDesktop().browse(temp.toURI());
    } catch (IOException e) {
        e.printStackTrace();
    }