Commons-IO 工具类FileUtils的文件复制操作

##Commons-IO 工具类FileUtils的文件复制操作

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

/*

  • COPY

  • */
    public class CIOTest05 {

    public static void main(String[] args) throws IOException {

    //复制文件81.jpg-->811.jpg
    // FileUtils.copyFile(new File("Scanner/src/IO_study02/81.jpg"),new File("Scanner/src/IO_study04/811.jpg"));
    
     //复制文件到目录
    // FileUtils.copyFileToDirectory(new File("Scanner/src/IO_study04/811.jpg"),new File("Scanner/src/IO_study04/eg"));
    
     //复制目录到目录,包括文件夹和子孙级
    // FileUtils.copyDirectoryToDirectory(new File("Scanner/src/IO_study04/eg"),new File("Scanner/src/IO_study04/eg2"));
    
     //拷贝URL内容
    // String url = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1588008595842&di=91fece1a752f9d9b85aafadbbf82ce60&imgtype=0&src=http%3A%2F%2Fh.hiphotos.baidu.com%2Fzhidao%2Fpic%2Fitem%2F4afbfbedab64034f9fddff01a9c379310a551da0.jpg";
    // FileUtils.copyURLToFile(new URL(url),new File("Scanner/src/IO_study04/eg2.jpg"));
    
     String datas = IOUtils.toString(new URL("http://www.163.com"),"GBK");
     System.out.println(datas.substring(0,500));
    

    }
    }

你可能感兴趣的:(Commons-IO,java)