Redirect standart output to file

i want to ask how to redirect standart output to file,if i have statement like this System.out.println("hello"); i want hello not print in console but print to filethx
[188 byte] By [Xeon-YKa] at [2007-10-3 4:39:22]
# 1
System has a setOut() method you can pass a PrintStream reference to. Read the API.The question is: why do you want to change System.out if you simply want to print to a file, when you simply could use a PrintWriter wrapped around a FileWriter?
CeciNEstPasUnProgrammeura at 2007-7-14 22:43:17 > top of Java-index,Java Essentials,Java Programming...
# 2
When you run the program from a command prompt, you can redirect the whole standard output asjava -Ddefines -options ...whatever>outputfile
BIJ001a at 2007-7-14 22:43:17 > top of Java-index,Java Essentials,Java Programming...
# 3

Here is sample code for that:

static{

try {

PrintStream obj_ps = new PrintStream(new FileOutputStream("internal.log"));

System.setOut(obj_ps);

System.setErr(obj_ps);

}

catch (FileNotFoundException ex) {

JOptionPane.showMessageDialog(null, "Error creating log file", "Error", JOptionPane.ERROR_MESSAGE);

}

}

k5ma at 2007-7-14 22:43:17 > top of Java-index,Java Essentials,Java Programming...