java文档中说PrinterJob类中的getPrinterJob()方法无论返回的打印机是否可用都不会返回一个null值。我查阅过一些文献有介绍说可以用getPrintService()方法测试返回的数值是否为null来...
java文档中说PrinterJob类中的getPrinterJob()方法无论返回的打印机是否可用都不会返回一个null值。我查阅过一些文献有介绍说可以用getPrintService()方法测试返回的数值是否为null来判断打印机是否可用。
但是我不明白的是,在什么情况下打印机不可用?高分求解详细的解答。
java文档参考原文:
PrinterJob java.awt.print.PrinterJob.getPrinterJob()
"
Creates and returns a PrinterJob which is initially associated with the default printer. If no printers are available on the system, a PrinterJob will still be returned from this method, but getPrintService() will return null, and calling print with this PrinterJob might generate an exception. Applications that need to determine if there are suitable printers before creating a PrinterJob should ensure that the array returned from lookupPrintServices is not empty.
"
相关文档原文参考:
"
One point you should keep in mind is that sometimes a printer may not be available on the machine on which your code is running.In this case the getPrintService() method will return null,so it's a good idea to call the method and test the reference that is returned,even if you don't want to obtain details of the printer.
"
请排除打印机损坏的情况。
展开