close

The System.out will be changed to test file after the instruction , System.setOut(new PrintStream("test")) ,

is executed.

so , if we want to redirect the std out from file to screen , we must record the System.out first , 

and then we can use this record to redirect the std out.

 

try

{

PrintStream oringinal = System.out;

System.setOut(new PrintStream("test"));

System.setOut(oringinal);

File dir = new File("userInfor");

String[] children = dir.list();

if (children ==null)

{

System.out.println("There is no file in this directory");

}

else

{

for(int i=0 ; i<children.length ; i++)

{

System.out.println(children[i]);

}

}

}

catch(IOException e)

{

System.out.println(e);

}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 JerryCheng 的頭像
    JerryCheng

    KwCheng's blog

    JerryCheng 發表在 痞客邦 留言(0) 人氣()