我正在尝试用Java编写一个PDF文件来说出这些文字hello neckbeards但是当我运行我的程序时,Adobe Reader会打开,但是出现了一个错误:
There was an error opening this document.
The file is already open or in use by another application.
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
import java.awt.Desktop;
import java.io.*;
public class count10 {
public static void main(String[] args) throws Exception {
File tempfile = File.createTempFile("report", ".pdf");
FileWriter pfile = new FileWriter(tempfile);
pfile.write("hello neckbeards");
Desktop dtop = null;
if (Desktop.isDesktopSupported()) {
dtop = Desktop.getDesktop();
}
if (dtop.isSupported(Desktop.Action.OPEN)){
String path = tempfile.getPath();
dtop.open(new File(path));
}
}
}
Run Code Online (Sandbox Code Playgroud)