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 |
Explain public static void main(string args[]) in java.
What are the important methods of java exception class?
Difference between default and protected access specifiers?
what is main difference between architecture,framework and design pattren
What is the difference between preemptive scheduling and time slicing?
what is a static block?
What does bitwise or mean?
Which is dependent variable?
When should I use stringbuffer?
What are the advantages of java over cpp?
How to create com object in Java?
Name the package that always imported by default?