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(file);// 构造待打印的文件流
// DocAttributeSet das = new HashDocAttributeSet();
// Doc doc = new SimpleDoc(this,flavor, das);// 建立打印文件格式
//// job.print(doc, pras);// 进行文件的打印
// } catch (Exception e) {
// e.printStackTrace();
// }
// }如上代码,打印出来的中文都是乱码.
如果把第一句 改成:DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE
将出现如下异常:
data is not of declared type.
请教高手这个问题的解决方法.