我不确定这是否可以解决您的问题,但是我使用以下命令打印文本文件
FileInputStream textStream;textStream = new FileInputStream(FILE_NAME);DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;Doc mydoc = new SimpleDoc(textStream, flavor, null); PrintService[] services = PrintServiceLookup.lookupPrintServices( flavor, aset); PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService(); if(services.length == 0) { if(defaultService == null) { //no printer found } else { //print using default DocPrintJob job = defaultService.createPrintJob(); job.print(mydoc, aset); } } else { //built in UI for printing you may not use this PrintService service = ServiceUI.printDialog(null, 200, 200, services, defaultService, flavor, aset); if (service != null) {DocPrintJob job = service.createPrintJob();job.print(mydoc, aset); } }您可能不需要ServiceUI,但是我认为您可以使用PrintService
[]服务来获取可用于打印的打印机列表。使用输入流和Doc类,您可以将文件打印到打印机。



