java流--处理流(print)

java流分为节点流和处理流。

按处理数据类型分为:字符流和字节流; 

         今天接触到了java的流,并用处理流写了一个工具类,用于实现改变sys.out.print的默认输出路径。

(由原先console窗口输出改为文件路径输出。),此方法可用于日志记录的实现。

下面是我的实现方法;

public static void printChange(String filePath,boolean isNo){
PrintStream ps = null;
try {
FileOutputStream f=new FileOutputStream(filePath,isNo);
ps=new PrintStream(f);//加一层处理流
if(ps!=null){
System.setOut(ps);
}
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
System.out.print(df.format(new Date()));// new Date()为获取当前系统时间
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

猜你喜欢

转载自blog.csdn.net/qq_41819327/article/details/79511614
今日推荐