String filename = "e:\\test.txt";
//String filename = "e:\\test.jpg";
        PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
        DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
        PrintService printService[] =  PrintServiceLookup.lookupPrintServices(flavor, pras);
        PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
        PrintService service = ServiceUI.printDialog(null, 200, 200, printService, defaultService, flavor, pras);
        if (service != null) {
            DocPrintJob job = service.createPrintJob();
            DocFlavor[] d = service.getSupportedDocFlavors();
            FileInputStream fis = new FileInputStream(filename);
            DocAttributeSet das = new HashDocAttributeSet();
            Doc doc = new SimpleDoc(fis, flavor, das);
            InputStream i = doc.getStreamForBytes();
            job.print(doc, pras);
            Thread.sleep(10000);
        }
我用这样只能打印出图片,不能打印txt和word等字符阿,应该是flavor的类型的问题,可是我的HP打印机不支持其他类型。应该怎样改才能打印字符呢?
在线等。。