FileUtils工具类

导入第三方jar:commons-io

@Test
    public void test7() throws IOException {
        File srcFile = new File("hello.txt");
        File destFile = new File("hello2.txt");
        //FileUtils.copyFile(srcFile,destFile);//复制文件

        String data = FileUtils.readFileToString(srcFile, "UTF-8");//读文件
        System.out.println(data);

        FileUtils.writeStringToFile(destFile,"你好333","UTF-8",true);//写文件,文件不存在时会自动创建
    }
  

  

 

posted @ 2022-09-02 22:38  Mr_sven  阅读(29)  评论(0编辑  收藏  举报