Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Creating a textfile with program output.

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Creating a textfile with program output.

    I'm trying to copy my program output to a text file and still have it be displayed in the console. How would i go about doing this?
    Thanks.


  2. #2
    Member
    Join Date
    Aug 2013
    Posts
    95
    Thanks
    3
    Thanked 14 Times in 14 Posts

    Default Re: Creating a textfile with program output.

    Use system.out.println() any where you write to your file. Just mirror the printing statements you do to your file with system.out.prints to the console. Simple as that.

  3. #3
    Junior Member
    Join Date
    Sep 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Creating a textfile with program output.

    I'm not sure i understand what you're saying, I have my program done and it outputs a bunch of text in the console how do i get it to create a text file with that output when the program is run.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Creating a textfile with program output.

    Some OSs have command line operators to pipe a program's output into a file. Is that what you are asking about? Do a search for your OS to see what the operator is.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Aug 2013
    Posts
    95
    Thanks
    3
    Thanked 14 Times in 14 Posts

    Default Re: Creating a textfile with program output.

    Check this link out. It shows you some examples of writing to a text file in java. Multiple ways.

    Java - Streams, Files and I/O

  6. #6
    Junior Member
    Join Date
    Sep 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Creating a textfile with program output.

    i used System.setOut but that redirects the output to the text file and the console is left blank.

  7. #7
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Creating a textfile with program output.

    Cornix' excellent and helpful response was moved the tutorial section.

Similar Threads

  1. Read Textfile from server, memory issue
    By XxxXxx896 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: May 11th, 2013, 06:21 AM
  2. How to split nextline in textfile using Buffered Reader?
    By shen_punkz21 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 2nd, 2013, 07:08 AM
  3. Buferred Writer in TextFile
    By shen_punkz21 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 2nd, 2013, 02:37 AM
  4. New beginner textfile and forms etc.
    By AnnieViola in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: October 18th, 2011, 07:29 AM
  5. Creating Methods for Input/Output Files
    By PapaGL0VE in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: November 17th, 2010, 10:07 AM