Java 如何获取已安装打印机的列表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/410967/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I get a list of installed printers?
提问by Thomas Zuberbühler
I'm searching for a possibility to get a list of installed printers. I'm using JDK 1.6 with a Windows operating system. Does anyone know a solution?
我正在寻找获取已安装打印机列表的可能性。我在 Windows 操作系统上使用 JDK 1.6。有谁知道解决方案?
Thank you in advance.
先感谢您。
采纳答案by Pedro Henriques
Just wanted to add a little snippet:
只是想添加一个小片段:
import javax.print.*;
class Test {
public static void main (String [] args)
{
PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null);
System.out.println("Number of print services: " + printServices.length);
for (PrintService printer : printServices)
System.out.println("Printer: " + printer.getName());
}
}
回答by Ronald Blaschke
I haven't used this myself, but maybe javax.print.PrintServiceLookup
contains what you are looking for.
我自己没有使用过这个,但可能javax.print.PrintServiceLookup
包含您正在寻找的内容。
回答by alain
Update for the newer Java packages
更新较新的 Java 包
just modify:
只需修改:
import javax.print.PrintService;
import javax.print.PrintServiceLookup;