Java如何获得默认的打印服务(打印机)?
要查找默认的打印服务,我们可以使用javax.print.PrintServiceLookupclasslookupDefaultPrintService()方法。
package org.nhooo.example.print;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
public class GetPrinter {
public static void main(String[] args) {
//获取此环境的默认打印服务。当返回null
// 找不到默认的打印服务。
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
if (service != null) {
String printServiceName = service.getName();
System.out.println("Print Service Name = " + printServiceName);
} else {
System.out.println("No default print service found.");
}
}
}上面的代码片段的结果:
Print Service Name = HP LaserJet P1005
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短