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

What are the different types of collections in java?

0 Answers  


Why a dead thread occurs?

0 Answers  


What is difference between length and length() method in java ?

0 Answers  


How do you remove duplicates from an array in java?

0 Answers  


What is string made of?

0 Answers  


Why do we use bufferedreader?

0 Answers  


Can you run the product development on all operating systems ?

1 Answers  


Is arraylist dynamic in java?

0 Answers  


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

1 Answers   ABC, KPIT,


What for read() function?

3 Answers  


Why string is immutable with example?

0 Answers  


Is static variable stored in heap?

0 Answers  


Categories