3 Replies Latest reply: Apr 26, 2008 2:50 PM by 807601 RSS

    Help with printing a txt file

    807601
      Hi, Im having some (a lot) of trouble getting my head round how to actually print a text file.

      Literally i want no formatting, no user interaction or anything, it just has to print a text file, im looking to create a method that is called by another method.

      I know everyone says read the API, however im really not finding it helpfull at all, so if anyone could give me a basic example, or just somewhere to start i'd be really gratefull.

      Thanks
      Alan
        • 1. Re: Help with printing a txt file
          807601
          Have a look at:

          http://forum.java.sun.com/thread.jspa?threadID=566988&messageID=2799536

          and

          http://www.exampledepot.com/egs/javax.print/BasicPrint.html
          • 2. Re: Help with printing a txt file
            807601
            If you are using Java J2SE 6 (which I would recommend unless you have a good reason not too) then it is
            as simple as this.



            import java.awt.Desktop;
            import java.io.File;
            
            public class Printer {
                 
                 public static void main(String[] args) throws Exception {
                      Desktop.getDesktop.print(new File("c:\\test.txt"));
                 }
            }
            http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/desktop_api/

            http://java.sun.com/javase/6/docs/api/java/awt/Desktop.html#print(java.io.File)
            • 3. Re: Help with printing a txt file
              807601
              Thanks for all the posts guys, sorry I havent replied earlier.

              Annoyingly i cant use the Java 6 solution as this is for a uni project and they dont have java 6 running on the computers there, and as its for my final 2nd year presentation I dont dare risk trying to get it all installed.

              Going to have a look through the links posted and see If I can come up with something to print the file.