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 |
How would you dynamically allocate memory to an array?
What is the catch or declare rule for method declarations?
What are loops in java?
How many threads can I run java?
Can a constructor be protected?
How do you end a program?
what is the swingutilities.invokelater(runnable) method for? : Java thread
Is java hashset ordered?
Program to Find the second largest element in an array.
How does a for loop work java?
What are the parts of methodology?
What is constructor
9 Answers Manforce, Tech Mahindra,