There are a few things you can do. To answer your question, you would do something like
System.setOut(new FileOutputStream(myFile));
However, I would use a registration framework to write to a file. First, initialize your registrar somewhere:
FileHandler handler = new FileHandler("mylogfile.txt", true); // True to append to file, false to overwrite.
Logger logger = Logger.getLogger(getClass().getName());
logger.addHandler(handler);
Then you can use the method that you call every time you want to print something, for example:
public void output(String message, boolean toConsole, boolean toFile) {
if (toConsole) {
System.out.println(message);
}
if (toFile) {
m_logger.info(message);
}
}
, , . toConsole toFile , .