read输入流与writer输出流的对比

package io.day4;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.Arrays;

public class Test {

  public static void main(String[] args) throws Exception {
  read();//输入流
  write();//输出流

  }

   //输出流

  private static void write() throws Exception {
  Writer wt = new FileWriter("Test/xy.txt");
  char[] c = {'谁','是','大','傻','逼'};
  wt.write(c);
  wt.close();
  }

  //输入流

  private static void read() throws Exception {
  Reader rd= new FileReader("Test/xy.txt");
  int b=rd.read();                //读取单行字符
  System.out.println((char)b);
  char[] chars = new char[10];          //读取10个字符
  int length = rd.read(chars);
  System.out.println(Arrays.toString(chars));
  rd.close();
   }
}

posted @ 2017-05-21 19:47  孤独患者xy  阅读(182)  评论(0编辑  收藏  举报