IO流(2)
下载地址
Commons IO – Download Apache Commons IO
添加jar包:在File->project structure-> Libraries下面添加
FileUtils的使用一
public class FileUtilsDemo_30 {
public static void main(String[] args) throws Exception{
String content = FileUtils.readFileToString(new File("E:\\hwcsdxdwads.txt"),"utf-8");
System.out.println(content);
}
}
FileUtils的使用二
public class FileUtilsDemo_31 {
public static void main(String[] args) throws Exception{
FileUtils.copyDirectory(new File("E:\\a"),new File("D:\\a"), new FileFilter() {
// 从文件拷贝时的过率条件
@Override
public boolean accept(File pathname) {
if (pathname.isDirectory() ||pathname.getName().endsWith("html")){
return true;
}
return false;
}
});
}
}
FileUtils的使用三
public class FileUtilsDemo_32 {
public static void main(String[] args) throws Exception{
String context = IOUtils.toString(new FileInputStream("E:\\xu.txt"),"utf-8");
System.out.println(context);
}
}