Probably this thread is a duplicate but can someone guide? I want to write the java program output to console and file at the same time. I know that i can send output to console with this piece of code
    PrintStream orgStdout = null;
    PrintStream fileStdout = null;
    orgStdout = System.out;
    try {
        fileStdout = new PrintStream(new FileOutputStream("C:\\testlogger.txt"));
        System.setOut(fileStdout);
        System.out.println("==============");
        for (int i = 0; i < 10; i++){
            System.out.println("" + i);
        }
        System.out.println("==============");
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
but how to keep output on console and on file as well??
P.S: not looking for an option where i output in file and display it console in different thread.
 
     
     
     
     
    