021.5 IO流——字符流

###############基本功能

FileWriter fw = new FileWriter("xxx.txt");
fw.write("哈喽");
fw.close();

FileReader fr = new FileReader("xxx.txt");
int ch = 0;
while((ch = fr.read()) != -1){
    System.out.println((char)ch);
}
fr.close();

###############字符流缓冲区
写入

private static void writeTextByBuffered() throws IOException
{
    FileWriter fw = new FileWriter("char_xxx.txt");
    BufferedWriter bw = new BufferedWriter(fw);
    bw.write("小红");
    bw.newLine();
    bw.write("小花,小华");
    bw.flush();
    bw.close();
}

读取

private static void writeTextByBuffered() throws IOException
{
    FileWriter fw = new FileWriter("char_xxx.txt");
    BufferedWriter bw = new BufferedWriter(fw);
    bw.write("小红");
    bw.newLine();
    bw.write("小花,小华");
    bw.flush();
    bw.close();
}

读取键盘录入信息,Scanner=流+正则表达式。方法是按照某种规则在读取数据
BufferedReader bufr = new BufferedReader(new InputStreamReader(System.in);
bufr.readLine();

 

posted @ 2018-05-05 15:38 _nbloser 阅读(...) 评论(...) 编辑 收藏