gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 08:31:22 26 4
gpt4 key购买 nike

我尝试过这个,但没有成功:

         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());

最佳答案

对我来说,稍微修改一下形式即可:

    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();
}

关于java - (JAVA) 如何在浏览器中打开临时 htm 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3266566/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com