Created
October 18, 2012 12:41
-
-
Save atilacamurca/3911550 to your computer and use it in GitHub Desktop.
A piece of code for printing directly to the printer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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