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 are the different types of collections in java?
Why a dead thread occurs?
What is difference between length and length() method in java ?
How do you remove duplicates from an array in java?
What is string made of?
Why do we use bufferedreader?
Can you run the product development on all operating systems ?
Is arraylist dynamic in java?
There is a Banking application. It has 2 types of account, Savings and Current. Write a method calculateInterest by passing an ArrayList of these account objects and calculate Interest accordingly. Write code for this situation
What for read() function?
Why string is immutable with example?
Is static variable stored in heap?