如何检查打印机是否通过Java连接到您的PC? [英] How to check Printer is connected or not to your PC by Java?

查看:140
本文介绍了如何检查打印机是否通过Java连接到您的PC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够获得之前在我的PC上安装的打印机的名称。但现在它没有物理连接到我的电脑。在使用Java转移到Print()之前,我该如何检查它。

I am able to get the name of printer which I had installed previously on my PC.But now its not physically connected to my pc. How should I check it first before moving to Print() in Java.

推荐答案

您可以使用 PrinterState 属性,如果您的打印机支持。

You can use PrinterState attribute if it is supported by your printer.

这样的事情:

PrintServiceAttributeSet printServiceAttributes = selectedService.getAttributes();
PrinterState printerState = (PrinterState) printServiceAttributes.get(PrinterState.class);
       if (printerState != null){
          System.out.println(printerName + " is online");
       } 
       else {
          System.out.println(printerName + " is offline");
       }

这篇关于如何检查打印机是否通过Java连接到您的PC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆