文件工具类FileUtils的使用

来源:互联网 发布:mysql.sock不见了 编辑:程序博客网 时间:2024/04/28 09:39

 

在apache的的常用包commons-io.jar中,有对文件处理的工具类FileUtils,了解这个类的使用,在开发中可以快速完成对文件的一些功能的处理

 

 

//文件1File file1;    //文件2File file2;       //复制文件 copy one file into another    FileUtils.copyFile(file1, file2);       //把文件内容转换为字符串  read a file into a String    String s1 = FileUtils.readFileToString(file1);       //把文件内容转换为字符串集合,每行为一个字符串对象 read a file into a list of Strings, one item per line    List<String> l1 = FileUtils.readLines(file1);       //获取目录下或者子目录下的文件,文件类型可以指定   return the list of xml and text files in the specified folder and any subfolders    Collection<File> c1 = FileUtils.listFiles(file1, { "xml", "txt" }, true);       //复制目录 copy one folder and its contents into another    FileUtils.copyDirectoryToDirectory(file1, file2);       //删除目录  delete one folder and its contents    FileUtils.deleteDirectory(file1);   


 

原创粉丝点击