📄 redirectexample.java
字号:
import java.io.*;import java.sql.Timestamp;class RedirectExample{ // Change this path if you are using unix or want another path public static final String FILE = "c:\\systemin.txt"; public static void main(String args[]) { try { // Create a file output stream and set the append = true flag FileOutputStream outStr = new FileOutputStream( FILE, true ); // create a print stream so that we can connect to System.out PrintStream printStream = new PrintStream( outStr ); // Tell System.out to redirect to the printStream that we've created System.setOut( printStream ); // Print out some text. It should not go to the console, but to the // text file created above. Timestamp now = new Timestamp( System.currentTimeMillis() ); System.out.println( now.toString() + ": This is text that should go to the file" ); // Close the open Resources outStr.close(); printStream.close(); } catch( FileNotFoundException ex ) { ex.printStackTrace(); System.exit( -1 ); } catch( IOException ex ) { ex.printStackTrace(); System.exit( -1 ); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -