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 |
why did you choose your career in IT?
What is integers and example?
What is the difference between private & public & friendly classes?
How can you read an integer value from the keyword when the application is runtime in java? example?
In java, how many ways you can take input from the console?
Explain the difference between throw and throws in java?
What is difference between module and function?
What is difference between iterator access and index access?
What are Interceptors?
Why hashmap is used in java?
What is meant by method overriding?
Difference between comparator and comparable in java?