zoukankan      html  css  js  c++  java
  • 329.-io流(字符-练习-复制文本文件二)

    //每次读取的字节长度,一般都是1024的倍数
    private static final int BUF_SIZE = 1024;

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    FileReader fr = null;
    FileWriter fw = null;
    try {
    fr = new FileReader("demo.txt");
    fw = new FileWriter("cope.txt");
    //定义一个数组容器,用来装读取的字节
    char[] buf = new char[BUF_SIZE];
    int len = 0;
    while ((len = fr.read(buf)) != -1) {
    fw.write(buf, 0, len);
    }

    } catch (Exception e) {
    // TODO: handle exception
    throw new RuntimeException("复制失败");
    }finally {
    if (fr != null) {
    try {
    fr.close();
    } catch (Exception e2) {
    // TODO: handle exception
    }
    }
    if (fw != null) {
    try {
    fw.close();
    } catch (Exception e2) {
    // TODO: handle exception
    }
    }

    }



    }

    每一步都是一个深刻的脚印
  • 相关阅读:
    leetcode165
    leetcode63
    leetcode92
    leetcode86
    捣鼓Haskell
    递归操作链表
    treap(堆树)
    贪心策略 — 分数背包
    LeetCode.21
    LeetCode.94
  • 原文地址:https://www.cnblogs.com/chzlh/p/9417725.html
Copyright © 2011-2022 走看看