java 打印机打印文件 中文乱码

程序如下 网上找到的一段程序

public static void main(String[] args) throws IOException {
// filetest();
File file = new File("D:/test.txt"); //获取选择的文件
//构建打印请求属性集
HashPrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
//设置打印格式,因为未确定类型,所以选择autosense
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(fis, flavor, das);
job.print(doc, pras);
} catch (Exception e) {
e.printStackTrace();
}
}
}
是中文的话会有乱码其他都好的 请教下如何改
还有打印格式应该怎么调整呢?我是想打印一个表格形式,但是txt文件很难控制格式
求教 谢谢了先 分数好说

你把工程的编码改成UTF-8再打印试试
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-12-02
用ireport吧设计格式吧,乱码就是编码格式的问题,多试试就好了。本回答被提问者采纳
相似回答