Skip to content

Instantly share code, notes, and snippets.

@atilacamurca
Created October 18, 2012 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save atilacamurca/3911550 to your computer and use it in GitHub Desktop.
Save atilacamurca/3911550 to your computer and use it in GitHub Desktop.
A piece of code for printing directly to the printer.
package app;
import java.io.FileOutputStream;
import java.io.PrintWriter;
/**
* Example class for direct print
* @author atila
*/
public class Main {
public static void main(String[] args) {
try {
FileOutputStream fos = new FileOutputStream("/dev/usb/lp0");
PrintWriter printer = new PrintWriter(fos);
// print some text
printer.println("Hello world.");
printer.flush();
printer.println("I love MAD3 Linux.");
printer.flush();
// close and free the device
printer.close();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment