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



How could Java classes direct program messages to the system console, but error messages, say to a..

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

How could Java classes direct program messages to the system console, but error messages, say to a..

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

Post New Answer

More Core Java Interview Questions

Is an object null?

1 Answers  


What is serialization in java?

1 Answers  


What are nested classes in java?

1 Answers  


What do you mean by platform independence of Java?

1 Answers  


How to call a Stored Procedure from JDBC?

4 Answers   Satyam,


How to create a fecelet view?

1 Answers  


Why strings in java are called as immutable?

1 Answers  


Does java map allow duplicates?

1 Answers  


Accenture NJ mostly ask question on Collection like 1)How to sort Objcts and how treeset sort them 2)Explain mechanism of Hashcode finding in Java 3)Name some of the Sorted collection.

2 Answers   Accenture,


Can we overload the methods by making them static?

1 Answers  


What is the difference between jvm and jre? What is an interface?

1 Answers  


What is final keyword in java?

1 Answers  


Categories