字符流的读取与写入

作者: 晨曦_hero | 来源:发表于2017-09-22 08:44 被阅读1次

    public class Text08 {
    public static void main(String[] args) {
    FileReader fileReader = null;
    BufferedReader reader = null;
    FileWriter fileWtite = null;
    BufferedWriter write = null;
    try {
    fileReader = new FileReader("index.txt");
    reader = new BufferedReader(fileReader);
    fileWtite = new FileWriter("copy1.txt");
    write = new BufferedWriter(fileWtite);
    String str = "";
    while ((str = reader.readLine()) != null) {
    write.flush();//刷新缓冲区 ()
    write.write(str);
    write.write("\n");
    write.newLine();

    }
    } catch (FileNotFoundException e) {
        System.out.println("文件找不到"+e.getMessage());
    }catch (IOException e) {
        System.out.println("io读写异常"+e.getMessage());
    }finally{
        try {
            reader.close();
            write.close();
            fileReader.close();
            fileWtite.close();
            
        } catch (Exception e2) {
            System.out.println("文件关闭异常"+e2.getMessage());
        }
    }
    

    }
    }

    相关文章

      网友评论

        本文标题:字符流的读取与写入

        本文链接:https://www.haomeiwen.com/subject/ajpxextx.html