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 |
Can final class have constructor?
How many threads can java run?
Explain the public class modifier?
What are jee technologies?
Difference between string, string builder, and string buffer?
What is a double vs float?
Justify your answer that you can't define a method inside another method in java, if you can then how?
What do heavy weight components mean in java programming?
What is the size of int?
What is appletviewer?
Can a source file contain more than one class declaration?
Can we print null in java?