import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
public class RedirectOut {
public static void main(String[] args) {
try {
FileOutputStream fil = new FileOutputStream("out.txt");
PrintStream ps = new PrintStream(fil);
System.setOut(ps);
System.out.println("普通字符串");
RedirectOut ro = new RedirectOut();
System.out.println(ro);
ps.close();
fil.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
|
|