printing in a Log File

A simple program

Class test

{

public static void main(String args[])

{

System.out.println("Working");

}

}

When this program is executed, it should not print "Working" in Command Prompt.

Instead it should create a file System.out.log and in that file it should write "working".

How to do it ?

[361 byte] By [PrabhuSai] at [2007-9-30 16:39:29]
# 1

Hi

I am giving you this program. hopefully this is the part you need. pls feel free to contact me in case of doubts.

bye

mm

import java.io.*;

public class any {

public static void main(String[] args)

{

FileOutputStream fos =null;

try

{

fos = new FileOutputStream(new File("C:\\temp\\Outlog.txt"));

PrintStream p = new PrintStream(fos);

System.setOut(p);

System.out.println("HELLO....");

System.out.println("How R U?");

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}finally

{

try

{

if(fos!=null)

fos.close();

} catch (IOException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

}

}

}

MAHIM_MISHRA at 2007-7-6 0:34:38 > top of Java-index,Administration Tools,Sun Connection...