2011-08-03 41 views
3

我使用Java 1.6(JDK),Windows 7和虛擬圖像打印機驅動程序。Java:打印文件不起作用

我嘗試打印一些文件。

這裏是我的代碼

try {  

    System.out.println(" PrintServiceOverseer printFileToDefaultPrinter start "+ 
     fileName);    

    PrintService printService = PrintServiceLookup.lookupDefaultPrintService(); 

    System.out.println(" default Printer " + printService.getName()); 

    FileInputStream inputStream = new FileInputStream(new File(fileName)); 

    DocFlavor docFlavor = DocFlavor.INPUT_STREAM.AUTOSENSE; 

    Doc printDoc = new SimpleDoc(inputStream, docFlavor, null); 

    PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); 
    pras.add(new Copies(1)); 

    DocPrintJob printJob = printService.createPrintJob(); 

    printJob.print(printDoc, pras); 

    inputStream.close();  

    System.out.println(" PrintServiceOverseer printFileToDefaultPrinter end "); 
} catch (Exception ex) { 
     ex.printStackTrace(); 
} 

但它不工作。它不會打印任何內容,也不會拋出異常。代碼編譯並運行平穩,但沒有輸出。

你能給我一些指導嗎?

回答

0

我得到了同樣的問題,我通過更新我的打印機驅動程序解決了這個問題,我認爲您沒有安裝正確的驅動程序,您可能安裝了適用於您的打印機的驅動程序,但不適用。