IO里的各种流

IO 顾名思义为: in out 输入输出

File file = new File(“文件地址”);//通过这个方法创建一个文件对象file
FileOutputStream fos = new FileOutputStream(file);//输出原始字节流
FileInputStream fis = new FileInputStream(file);//读取原始字节流

上述方法只能对字节进行操作
如果想对字符进行操作的话,可以考虑使用Reader Writer 的子类FileReader FileWriter
FileReader fr = new FileReader(file);
FileWriter fw = new FileWriter(file);

将字节输入流装饰成字符输入流的方法:
InputStreamReader isr = new InputStreamReader(fis);
打印流,也是一种字符输出流,它的使用格式为:
PrintStream ps = new PrintStream(“D://d.txt”);
缓存读取流:将字符输入流转换为带有缓存可以一次读取一行的缓存字符输入流
FileReader fr = new FileReader(“D://d.txt”);
BufferedReader br = new BufferedReader(fr);
String text = br.readLine();
缓存输出流:
FileWriterr fw = new FileWriter(D://d.txt");
BufferedWriterr bw = new BufferedReader(fw);
bw.warite();

最后再记录一个收集异常的方法:
异常日志收集:
public static void main(String[] args) throws FileNotFoundException {
// TODO Auto-generated method stub
try {
String s = null ;
s.toString();
}catch(Exception e) {
PrintWriter pw = new PrintWriter(“D://bug.txt”);
SimpleDateFormat sdf = new SimpleDateFormat();
Date date = new Date() ;
pw.println(sdf.format(date));
e.printStackTrace(pw);
pw.close();
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值