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);
}
全站熱搜