下面一段程序希望使用打印机将文件中的内容打印出来。现在能够打印,但文件里的中文
显示为乱码符号,看起来应该是字库没设置好,请问应该如何解决?3x & bow!程序如下:
String filename = "D:\\test.txt";
PrintRequestAttributeSet pras = newHashPrintRequestAttributeSet();
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) {
DocPrintJob job = service.createPrintJob();
FileInputStream fis = new FileInputStream(filename);
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(fis, flavor, das);
job.print(doc, pras);
}
显示为乱码符号,看起来应该是字库没设置好,请问应该如何解决?3x & bow!程序如下:
String filename = "D:\\test.txt";
PrintRequestAttributeSet pras = newHashPrintRequestAttributeSet();
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) {
DocPrintJob job = service.createPrintJob();
FileInputStream fis = new FileInputStream(filename);
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(fis, flavor, das);
job.print(doc, pras);
}
try{
Process pp = Runtime.getRuntime().exec( "cmd /c start print D:\\test.txt");
pp.waitFor();
} catch(Exception e){System.out.println(e);}