(JAVA) How open a temp htm file in browser?
I tried this, but without sucess:
File temp = File.createTempFile("document", ".htm");
BufferedWriter out = new BufferedWriter(new FileWriter(temp));
out.write开发者_如何学C("hi !!!");
out.close();
System.out.println(temp.toURI().toString());
java.awt.Desktop.getDesktop().browse(temp.toURI());
Works for me in slightly modified form:
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();
}
精彩评论