您的位置:首页 > 其它

System.out.print重定向到文件实例

2015-06-25 17:42 375 查看
该代码可以实现让System.out.print输出内容不再打印到控制台,而是输出到指定的文件中

<strong><span style="font-size:24px;">package com.zken.testcase;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;

public class TestSystemOut {

	public void redirectSystemOut() {

		try {

			System.setOut(new PrintStream(new FileOutputStream("systemOut.txt")));

		} catch (FileNotFoundException ex) {
			ex.printStackTrace();
			return;
		}

		System.out.println("Hello World!");

	}

	
	public static void main(String[] args) {
		new TestSystemOut().redirectSystemOut();
	}
}</span></strong>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: