我想用JAVA打印一个指定的TXT文件,代码如下 
                                     File testfile = new File("P:\\JADE3.1\\out.txt");
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
PrintService printService[] = PrintServiceLookup
.lookupPrintServices(flavor, pras);
PrintService defaultService = PrintServiceLookup
.lookupDefaultPrintService();
PrintService service = ServiceUI.printDialog(null, 200, 200,
printService, defaultService, flavor, pras);
if (service != null) {
try {
DocPrintJob job = service.createPrintJob();
FileInputStream fis = new FileInputStream(testfile);
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(fis, flavor, das);
job.print(doc, pras); } catch (Exception e) {
e.printStackTrace();
}
由于DocFlavor 不识别 字符流的,所以只能用字节流 FileInputStream,这样如果我TXT文件里有汉字的时候 打印出来就是乱码了,希望有高手大大给想个办法。可以加我Q382452595,万分感谢!已经困扰我两天了!!!