Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于java打印的后台处理程序消失_Java_Printing_Spooler - Fatal编程技术网

基于java打印的后台处理程序消失

基于java打印的后台处理程序消失,java,printing,spooler,Java,Printing,Spooler,我想从java打印文本文件,但后台打印程序消失了。如果我直接从记事本上打印它,它就会工作。(我也尝试了pdf和图像,但在java中不起作用) 我注意到java中的数据类型是原始的,但记事本中的数据类型是nt emf 1008 这是我的密码: public void print(){ String bon = "something to print" BufferedWriter writer = null; try { writer = new Buff

我想从java打印文本文件,但后台打印程序消失了。如果我直接从记事本上打印它,它就会工作。(我也尝试了pdf和图像,但在java中不起作用)

我注意到java中的数据类型是原始的,但记事本中的数据类型是nt emf 1008

这是我的密码:

public void print(){
    String bon = "something to print"

    BufferedWriter writer = null;
    try {
        writer = new BufferedWriter(new FileWriter("D:/printer/bon.txt"));
    } catch (IOException ex) {
    }
    try {
        writer.write(bon);
        writer.close();
    } catch (IOException ex) {

    }
    FileInputStream textstream = null; 
    try { 
        textstream = new FileInputStream("D:/printer/bon.txt"); 
    } catch (FileNotFoundException ffne) { 
    } 
    if (textstream == null) { 
       return; 
    } 
    // Set the document type
    DocFlavor myFormat = DocFlavor.INPUT_STREAM.AUTOSENSE;
    // Create a Doc
    Doc myDoc = new SimpleDoc(textstream, myFormat, null); 
    // Build a set of attributes
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); 
    aset.add(new Copies(1)); 
    aset.add(MediaSizeName.ISO_A5);

    // discover the printers that can print the format according to the
    // instructions in the attribute set
    PrintService services =
            PrintServiceLookup.lookupDefaultPrintService();
    // Create a print job from one of the print services
    if (services!=null) { 
        System.out.println(services.getName());
        System.out.println(services.isDocFlavorSupported(myFormat));
        DocPrintJob job = services.createPrintJob(); 
        try { 

                job.print(myDoc, aset); 

                textstream.close();
        } catch (PrintException pe) {
            Logger.getLogger(pe.getMessage());
            System.out.println("error1");
        } catch (IOException ex) { 
            Logger.getLogger(Printing.class.getName()).log(Level.SEVERE, null, ex);
        } 
    }
    else{
        System.out.println("printer tidak ada");
    }
}

不要默默地吞下注意到的例外情况,但当它通过该点时,打印作业会显示一会儿,然后消失