How could Java classes direct program messages to the
system console, but error messages, say to a file?
Answers were Sorted based on User's Feedback
Answer / munna
import java.io.*;
class Err
{
public static void main(String[] args) throws Exception
{
PrintStream ps=new PrintStream(new
FileOutputStream("output.txt"));
System.setErr(ps);
System.setOut(ps);
System.out.println("fdffdfdffffff........");
}
}
Is This Answer Correct ? | 8 Yes | 0 No |
Answer / biru3121
The class System has a variable out that represents the
standard output, and the variable err that represents the
standard error device. By default, they both point at the
system console. This how the standard output could be re-
directed:
Stream st = new Stream(new FileOutputStream("output.txt"));
System.setErr(st);
System.setOut(st);
Is This Answer Correct ? | 6 Yes | 1 No |
What is immutable in java?
What are the parts of a method?
What is used of static keyword in java?
what is the use of declaring constructor as private?
5 Answers Cyient, IVY Technologies, Sai Softech, Virtusa,
What are different types of inner classes ?
Does java trim remove newline?
What is the indent key?
What does this () mean in java?
How do you sort in java?
What is the difference(or similarity if there are some) between object and a variable?
Why to use nested classes in java?
why java is better then .net?