Results 1 to 2 of 2
  1. #1
    Propinquity is offline Member
    Join Date
    Oct 2013
    Posts
    63
    Rep Power
    0

    Default How do I print my output file?

    I have printed the result of my program into an output file.
    For some reason I can't figure out how to get the file output.txt to actually print.
    I've tried printing it like I would normally print a file but it's not working.

    Java Code:
    final PrintStream console = System.out;
    			File file = new File("output.txt");
    			PrintStream out = new PrintStream(new FileOutputStream(file));
    			System.setOut(out);
    			System.out.println(collection.toString());
    			
    			System.setOut(console);
    //what do I do after this?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default Re: How do I print my output file?

    You have opened a FileOutputStream, kept the original System.out (a clever thing to do) and set System.out to another PrintStream that wras your FileOutputStream; you can print to it as always but when you're done you have to close the PrintStream again.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. how to print bold output
    By jihad in forum New To Java
    Replies: 1
    Last Post: 01-16-2012, 08:27 PM
  2. How to Print every tenth integer in my output
    By jim01 in forum New To Java
    Replies: 13
    Last Post: 04-16-2011, 03:00 AM
  3. Print Variable From One Class to Output on another.
    By Lyricid in forum New To Java
    Replies: 8
    Last Post: 02-27-2010, 01:56 PM
  4. Print the text file and print preview them
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-22-2008, 11:04 PM
  5. how to print output on same line in 'while loop'?
    By acidblue in forum New To Java
    Replies: 5
    Last Post: 12-13-2007, 02:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •