始终选择默认打印机,而不是指定的JAVA打印机

始终选择默认打印机,而不是指定的JAVA打印机,java,printing,Java,Printing,我有一个java打印程序,但出于某种原因,它总是选择默认打印机(8600),即使我传递了一个值(比如xps for printer),我做错了什么,如何让它选择所需的打印机 这是我的密码: PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null); System.out.println("Number of print services: " + printServices

我有一个java打印程序,但出于某种原因,它总是选择默认打印机(8600),即使我传递了一个值(比如xps for printer),我做错了什么,如何让它选择所需的打印机

这是我的密码:

 PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null);
        System.out.println("Number of print services: " + printServices.length); //tells me how many print services are isntalled on the server.

        for (PrintService printer2 : printServices) {
            System.out.println("Printer: " + printer2.getName()); //prints out the names of all printers on the server, testing purposes 
        } 


        PrintUtility.findPrintService(printer); // selects only the 8600 printer // EDIT now selects any printer with the name provided


        PrintService[] services =
                PrintServiceLookup.lookupPrintServices(psInFormat, null);
        //System.out.println("Printers avialiable are " + services);
        System.out.println("Printer Selected " + services[Printerinx]);

        //PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();

        DocFlavor[] docFalvor = services[Printerinx].getSupportedDocFlavors();
        for (int i = 0; i < docFalvor.length; i++) {
            System.out.println(docFalvor[i].getMimeType());
        }
        if (services.length > 0) {
            DocPrintJob job = services[Printerinx].createPrintJob();
            try {
                job.print(myDoc, aset);
                System.out.print("Printing Doc");
            } catch (PrintException pe) {
                System.out.print(pe);
            }
        }

感谢

确定已解决,printerinx,我已选择可使用的打印机,第一台为0等,我已将其设置为printinx=“3”,因此它总是选择第四台打印机,这台打印机已被删除,每个打印机都已获得正确的printinx,现在它已正常工作

确定已解决,printerinx,我已经选择了可以使用的打印机,第一台为0,等等,我已经将其设置为printinx=“3”,所以它总是选择第四台打印机,这台打印机已被删除,每个打印机都有正确的printinx,现在它可以正常工作了

INFO: Number of print services: 7
INFO: Printer: Send To OneNote 2013
INFO: Printer: Microsoft XPS Document Writer
INFO: Printer: HP988FD1 (HP Officejet Pro 8600)
INFO: Printer: HP Officejet Pro 8600 (Network)
INFO: Printer: Fax - HP Officejet Pro 8600 (Network)
INFO: Printer: Fax
INFO: Printer: Adobe PDF
INFO: Printer Selected Win32 Printer : HP Officejet Pro 8600 (Network)
INFO: image/gif