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();

    }

    }

     

    }

  • 相关阅读:
    Md5
    hdu 2569 彼岸
    调用系统相机相冊
    白盒測试
    HDU 1501
    IOS常见错误分析解决(一直更新) 你值得收藏-综合贴
    读“程序猿生存定律”笔记
    Halcon导出的cpp, VC++环境配置
    POJ 1260 Pearls (动规)
    hdoj-1856-More is better【并查集】
  • 原文地址:https://www.cnblogs.com/mabel/p/6120882.html
Copyright © 2011-2022 走看看