Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8368105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:18:32+00:00 2026-06-09T13:18:32+00:00

I am new to Java and I am stuck at this part : I

  • 0

I am new to Java and I am stuck at this part :

I am trying to output the console output into a text file using JAVA .
But the problem is I have a While loop running and my code writes the output to the file but deletes the previous one .
I want to append the while loop output to file .

Any help is appreciated . Thanks In advance 🙂

PrintStream out = new PrintStream(new FileOutputStream("output.txt"));

System.setOut(out);

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:18:34+00:00Added an answer on June 9, 2026 at 1:18 pm

    You should perform the redirection once, and before you do anything else. i.e. before you enter your loop.

    Note (also) that your shell can redirect to a file, and that might be preferable to changing the destination of System.out. That’s feasible but perhaps unexpected for someone who’s going to debug your code in the future and wonder where their output is going…

    Or perhaps consider a logging framework ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to Java and trying to solve the problem below So this
i have a text file with database table data in it and im trying
i am developing a GUI using Java Swing. but i got stuck here. Is
im stuck in this terrible problem, I have a SOAP based webservice implemented in
I'm a Java newbie and stuck with this: BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));
I'm trying to import a node from a base-document into a new document but
I have the following code adding an ActionListener to a JTextField: chatInput.addMouseListener(new java.awt.event.MouseAdapter() {
I have the following snippet of java code: final Class<?> junitCoreClass = AccessController.doPrivileged( new
I have written an image processing application with the GUI part written in Java
I have just started with Gui Programming in netbeans (Using the template Java Desktop

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.