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 接亲祝福语简短10字
16 新年祝福语大全简短感谢
17 闺蜜小孩祝福语简短
18 祝福语大全短句简短英语