Share this page 

Print text to a printer easilyTag(s): IO

A quick and simple way to output some text to a printer is to print to OS logical device attached a printer.

For example, on a Windows machine :


public class SimplePrinting {
  public static void main(String[] args) {
    try {
      FileWriter out = new FileWriter("lpt1");
      out.write("Hello world");
      out.write(0x0D); // CR
    catch (IOException e) {