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 :

import java.io.FileWriter;

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

blog comments powered by Disqus