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 is string substring?
how to prepare for IT Officers Interview in Banks
0 Answers TATA, Tata Steel Limited,
what is actual real time using of oops concepts in projects(Interface,polymorphism.abstraction.........)
What is numeric function?
What is a for loop in java?
How do you override a private method in java?
When can we say that threads are not lightweight process in java?
Can static methods be overridden?
What is meant by Java ?
What happens to a static var that is defined within a method of a class?
StringBuilder s = new StringBuilder("Hello Mom");s.append(",I mean,Mother"); Response.Write(s.ToString()); String s = "Hello Mom"; s+ = ",I mean Mom"; Response.Write(s); Which is faster ? which uses the most memory?
when everything can be done by static block then why do we use main method?.