62,623
社区成员
发帖
与我相关
我的任务
分享
import java.io.*;
public class Test
{
FileOutputStream fos;
PrintStream ps;
//for storing the old PrintStream
PrintStream old;
public void filePrint( String outName )
{
try
{
fos= new FileOutputStream( new File( outName ) );
ps = new PrintStream( fos );
//store the old PrintStream
old = System.out;
//set new PrintStream
System.setOut( ps );
}
catch( IOException ioe )
{
}
finally
{
try
{
ps.close();
fos.close();
}
catch( IOException ioe )
{
}
}
}
public void consolePrint( String message, PrintStream old )
{
System.setOut( old );
System.out.println( message );
}
}
import java.io.*;
public class Test8
{
FileOutputStream fos;
PrintStream ps;
public void filePrint( String outName )
{
try
{
fos= new FileOutputStream( new File( outName ) );
ps = new PrintStream( fos );
//System.setOut( ps );
}
catch( IOException ioe )
{
}
}
public void consolePrint( String message )
{
System.out.println( message );
}
}