我試圖用Java編寫PDF文件說一個PDF hello neckbeards
但是當我運行我的程序,則Adobe Reader打開,但一個錯誤出現說的話:生成的Java
There was an error opening this document.
The file is already open or in use by another application.
這裏是我的代碼:
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));
}
}
}
由於幾個人在下面所提到的,iText的是要建立PDF文件的好方法。請在任何重大開發之前查看iText的許可證。 – hooknc 2011-04-18 16:17:41
哇。這不會成爲一項家庭作業嗎? – 2011-04-18 22:22:20
'@ neckbeard69' ** 1)**如果這是家庭作業,請用'homework'標記標記。 ** 2)**當您找到答案解決您的問題時,請在接近選票區域時通過檢查其**綠色勾號**接受**。謝謝! – 2011-10-12 18:22:09