Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

Explain public static void main(string args[]) in java.

0 Answers  


What are the important methods of java exception class?

0 Answers  


Difference between default and protected access specifiers?

0 Answers  


what is main difference between architecture,framework and design pattren

3 Answers  


What is the difference between preemptive scheduling and time slicing?

0 Answers  


what is a static block?

4 Answers  


What does bitwise or mean?

0 Answers  


Which is dependent variable?

0 Answers  


When should I use stringbuffer?

0 Answers  


What are the advantages of java over cpp?

0 Answers  


How to create com object in Java?

0 Answers  


Name the package that always imported by default?

4 Answers  


Categories