| | |
| | | package com.hx.util; |
| | | |
| | | import org.apache.commons.io.FileUtils; |
| | | |
| | | import java.io.*; |
| | | import java.net.URL; |
| | | |
| | | /** |
| | | * 文件读取工具类 |
| | |
| | | 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 { |