chenjiahe
2023-02-07 1b181507f2564bfd327cc3a8e5d75a8620c3d09d
src/main/java/com/hx/util/FileUtil.java
@@ -1,6 +1,9 @@
package com.hx.util;
import org.apache.commons.io.FileUtils;
import java.io.*;
import java.net.URL;
/**
 * 文件读取工具类
@@ -10,6 +13,23 @@
public class FileUtil {
    /**
     * @param pathUrl 网络路径
     * @return 文件
     */
    public static File getUrlFile(String pathUrl){
        File temp = null;
        try{
            URL url = new URL(pathUrl);
            temp = File.createTempFile("temp", ".xls");
            FileUtils.copyURLToFile(url, temp);
            temp.deleteOnExit();
        }catch (Exception e){
            throw new RuntimeException("通过URL获取文件出错",e);
        }
        return temp;
    }
    /**
     * 读取文件内容,作为字符串返回
     */
    public static String readFileAsString(String filePath) throws IOException {