Saturday, 21 August 2010

In system.out.println what is out and println ? Can this be redirected to a file ? How ?

Yes you can set FileOutputStream Object to override default out implementation as follows:
=================================================
File f = new File("testOut.txt");
FileOutputStream fos;
try {
fos = new FileOutputStream(f);
PrintStream pos = new PrintStream(fos);
System.setOut(pos);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
System.out.print("Hello world File");
=================================================

No comments:

Post a Comment