How would I go about printing text from a java program? (Java)

后端 未结 4 1896
鱼传尺愫
鱼传尺愫 2021-01-16 05:38

I don\'t even know if this is possible and I highly doubt it is, but if you can, can you please tell me how? I just want to know how to print some text from a printer.

4条回答
  •  [愿得一人]
    2021-01-16 06:20

    What you can do is write to a file and then you can use Desktop class to print it. for more infomation on desktop class go here

    here is the program
    
    
    import java.awt.Desktop;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    
    
    public class abc {
    
    
        public static void main(String[] args) throws IOException{
    
            BufferedWriter out = new BufferedWriter(new FileWriter("1.txt"));
            out.write("Hello this is a test");
            out.flush();
            out.close();
    
            File ff = new File("1.txt");
    
            Desktop desktop = Desktop.getDesktop();
          desktop.print(ff);
    
    }
    

    }

提交回复
热议问题