From 6946ac243a04efb1c0f969c284f983fddb417319 Mon Sep 17 00:00:00 2001 From: fwq <582742538@qq.com> Date: 星期五, 03 二月 2023 11:24:33 +0800 Subject: [PATCH] 修改文件转换方法 --- src/main/java/com/hx/util/FileUtil.java | 20 ++++++++++++++++++++ 1 files changed, 20 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/hx/util/FileUtil.java b/src/main/java/com/hx/util/FileUtil.java index 03e7fee..69a7d41 100644 --- a/src/main/java/com/hx/util/FileUtil.java +++ b/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 { -- Gitblit v1.8.0