zoukankan      html  css  js  c++  java
  • FileRW

    package

    filereader;

     

    import

    java.io.FileNotFoundException;

    import

    java.io.FileReader;

    import

    java.io.FileWriter;

    import

    java.io.IOException;

    import

    java.io.Reader;

    import

    java.io.Writer;

     

    public

    class FileRW {

     

    public void fileReaderWriter(String sourcePath, String destinationPath) throws IOException {

    Reader fr = new FileReader(sourcePath);

     

    char[] buffer = new char[1024];

     

    StringBuffer sb = new StringBuffer();

     

    int length = fr.read(buffer);

     

    while (length != -1) {

     

    sb.append(buffer);

    length = fr.read(buffer);

    }

     

    // System.out.println(sb);

     

    fr.close();

     

    Writer fw = new FileWriter(destinationPath);

    fw.write(buffer);

     

    if (null != fw) {

    fw.close();

    }

     

    }

     

    }

     

    package

    filereader;

     

    import

    java.io.IOException;

     

    public

    class FileRWTest {

     

    public static void main(String[] args) {

    FileRW frw=new FileRW();

    String sourcePath="Q:/Users/a496006.DMN1.000/Desktop/s.txt";

    String destinationPath="Q:/Users/a496006.DMN1.000/Desktop/d.txt";

     

    try {

    frw.fileReaderWriter(sourcePath, destinationPath);

    } catch (IOException e) {

    // TODO Auto-generated catch block

    e.printStackTrace();

    }

    }

     

    }

  • 相关阅读:
    【转】HEIF图片存储格式探秘
    【转】Maven项目中将配置文件打包到jar包中
    C++ 单词接龙
    vector vector int 初始化
    哈夫曼树的特点
    哈夫曼树的构造
    单链表的逆转(测试数据)
    单链表的逆转
    二叉搜索树的插入
    二叉搜索数的应用
  • 原文地址:https://www.cnblogs.com/mabel/p/6120882.html
Copyright © 2011-2022 走看看