public class Test{

	/*
	 * 标准的I/O重定向
	 * System.setIn(InputStream)
	 * System.setOut(PrintStream)
	 * System.setErr(PrintStream)
	 */
	public static void main(String[] args) throws IOException {
		PrintStream console = System.out;
		BufferedInputStream in = new BufferedInputStream(new FileInputStream("/home/estar/Test/a.java"));
		PrintStream out = new PrintStream("and.out");
		
		System.setIn(in);
		System.setOut(out);
		System.setErr(out);
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s = null;
		while ((s = br.readLine()) != null) {
			System.out.println(s);
		}
		out.close();
		System.setOut(console);
		
	}
}

  

 

相关文章:

  • 2022-12-23
  • 2021-08-05
  • 2021-07-22
  • 2021-04-30
  • 2021-09-04
  • 2022-01-06
  • 2021-12-19
  • 2021-04-16
猜你喜欢
  • 2021-05-21
  • 2021-09-25
  • 2021-12-10
  • 2021-10-15
  • 2021-09-25
相关资源
相似解决方案