java文件工具类FileUtils的使用(直接饮用就可以使用)

java 工具类的maven中央仓库

http://grepcode.com/file/repo1.maven.org/maven2/commons-io/commons-io/2.4/org/apache/commons/io/FileUtils.java#FileUtils


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

[html]  view plain copy print ?
  1. //文件1  
  2. File file1;      
  3. //文件2  
  4. File file2;      
  5.      
  6. //复制文件 copy one file into another      
  7. FileUtils.copyFile(file1, file2);      
  8.   
  9.      
  10. //把文件内容转换为字符串  read a file into a String      
  11. String s1 = FileUtils.readFileToString(file1);      
  12.   
  13.      
  14. //把文件内容转换为字符串集合,每行为一个字符串对象 read a file into a list of Strings, one item per line      
  15. List<String> l1 = FileUtils.readLines(file1);      
  16.   
  17.      
  18. //获取目录下或者子目录下的文件,文件类型可以指定   return the list of xml and text files in the specified folder and any subfolders      
  19. Collection<File> c1 = FileUtils.listFiles(file1, { "xml", "txt" }, true);      
  20.      
  21. //复制目录 copy one folder and its contents into another      
  22. FileUtils.copyDirectoryToDirectory(file1, file2);      
  23.      
  24. //删除目录  delete one folder and its

你可能感兴趣的:(java文件工具类FileUtils的使用(直接饮用就可以使用))