67,513
社区成员
发帖
与我相关
我的任务
分享
private void printFile()throws Exception{
String filePath = "C:\\s.txt";
File file = new File(filePath);
//构建打印请求属性集
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
//设置打印格式,因为未确定文件类型,这里选择AUTOSENSE
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
// 默认打印机
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
if(service != null){
//创建打印
DocPrintJob job = service.createPrintJob();
//构造打印流
FileInputStream fis = new FileInputStream(file);
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(fis,flavor,das);
job.print(doc, pras);
}
}