3 Replies Latest reply on Apr 26, 2008 7:50 PM by 807601

    Help with printing a txt file

      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.

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



          • 2. Re: Help with printing a txt file
            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"));

            • 3. Re: Help with printing a txt file
              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.