java基础.io流.打印流

打印流:
  该流提高打印方法,可以将各类进行打印
 
 字节打印流:printsteam  能直接操作文件
  构造函数能够接受的参数类型:
  1;file对象
  2,字符串路径。string
  3;字节输出流。outputstream
  没有字节输出流
 
 字符打印流:printwriter
  1;file对象
  2,字符串路径。string
  3,字节输出流。outputstream

  4,字符输出流,writer

public class Ioprint流 {
	public static void main(String[] args)throws IOException
	{
		BufferedReader buf = 
				new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("d:\\count.txt",true)),true);//true自动刷新
		String line= null;
		
		while((line = buf.readLine())!=null)
		{
				
			out.println(line);
			//out.flush();
		}
		out.close();
		buf.close();
				
	}
	
}

以下是一个异常信息的写入,通过print流

import java.io.IOException;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.xml.crypto.Data;

public class Io4yichangrizhi {
	public static void main(String[] args)throws IOException
	{
		try{
			int[] arr=new int[2];
			System.out.println(arr[3]);
		}
		catch(Exception e)
		{
			try{
				//Data d = new Date();
				Date d = new Date();
				SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				String s=sdf.format(d);//将时间格式化
				PrintStream ps = new PrintStream("e://exexeption.log");// 创建具有指定文件名称且不带自动行刷新的新打印流
				ps.print(s);
				System.setOut(ps);
			}
			catch(IOException e1)
			{
				throw new RuntimeException("创建失败");
			}
			e.printStackTrace(System.out);
		}
	}

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值