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

    }

    }

     

    }

  • 相关阅读:
    挖矿程序linux 删除
    本地复制vue项目
    新建vue项目
    CentOS7单用户模式
    CentOS6
    CentOS6-系统管理操作
    CentOS7-系统管理操作
    VMWare克隆虚拟机
    虚拟机网络模式设置为NAT
    VI/VIM编辑器
  • 原文地址:https://www.cnblogs.com/mabel/p/6120882.html
Copyright © 2020-2023  润新知