2
Contributors
7
Replies
12
Views
6 Years
Discussion Span
Last Post by JamesCherrill
0

Redirect System.out Something like...

String fileName = "whatever.txt";
final boolean append = true, autoflush = true;
PrintStream printStream = new PrintStream(new FileOutputStream(fileName, append),
                                    autoflush);
System.setOut(printStream);
0

I tried that code didn't work. I need all output including errors sent to the .txt file.

0

Thanks for the support but It doesn't print my "FLOCKA" or my error to the .txt file.

Check out my code

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;



public class test {
	public static void main(String[] args){

		System.out.println("FLOCKA");
		System.err.print("booo");	    
	    	try
	    	{
	    	
	    	

	    	String fileName = "whatever.txt";
	    	final boolean append = true, autoflush = true;
	    	PrintStream printStream = new PrintStream(new FileOutputStream(fileName, append),  autoflush);
	    	System.setOut(printStream);
	    	System.setErr(printStream);
	    	
	      
	    	}
	    	catch(IOException e)
	    	{
	    	System.out.println("Error during reading/writing");
	    	}
	    
	}

}

Edited by smoothe19: n/a

0

It would help if you redirected the output before sending it.
You need to run the redirection code when the app starts, then all subsequent out/err output goes to that file.

0

Ahahahaha oopsie i feel slow. Thank you JamesCherrill i googled/yahoo/bing search noone knew haha now everyone who searches the same will land on this topic :-D

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.