Eclipse控制台转向输出

可以通过System.setOut(PrintStream)将System.out转向至你自己的控制台
如果要刷新每一个被写到你的PrintStream中的字节的话,在PrintStream构造方法中指定自动刷新参数

 

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.sql.Timestamp;

public class MainClass {

	public static void main(String[] args) {

		try {
			String FILE = "systemin.txt";
			FileOutputStream outStr = new FileOutputStream(FILE, true);
			PrintStream printStream = new PrintStream(outStr);

			System.setOut(printStream);
			
			Timestamp now = new Timestamp(System.currentTimeMillis());
			System.out.println(now.toString()
					+ ": This is text that should go to the file");

			outStr.close();
			printStream.close();
		} catch (FileNotFoundException ex) {
			ex.printStackTrace();
			System.exit(-1);
		} catch (IOException ex) {
			ex.printStackTrace();
			System.exit(-1);
		}
	}
}
 

你可能感兴趣的:(java,eclipse,sql,Go)