From 55697aaa2e4974d5b443e731581e4c50609946b7 Mon Sep 17 00:00:00 2001 From: guang <guang@guang.com> Date: 星期五, 28 七月 2023 11:13:30 +0800 Subject: [PATCH] 增加企业微盘操作工具类 --- src/main/java/com/hx/util/FileUtils.java | 37 +++++++++++++++++++++++++++++++++++++ 1 files changed, 37 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/hx/util/FileUtils.java b/src/main/java/com/hx/util/FileUtils.java index 6911a87..7da1769 100644 --- a/src/main/java/com/hx/util/FileUtils.java +++ b/src/main/java/com/hx/util/FileUtils.java @@ -7,6 +7,7 @@ import java.io.*; import java.net.FileNameMap; +import java.net.URL; import java.net.URLConnection; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -625,5 +626,41 @@ return type; } + public static File httpUrlFile(String netUrl) throws IOException { + File file = File.createTempFile("temp123", ".xls"); + InputStream inStream = null; + FileOutputStream os = null; + + try { + file = File.createTempFile("net_url", ".jpg"); + URL urlfile = new URL(netUrl); + inStream = urlfile.openStream(); + os = new FileOutputStream(file); + + byte[] buffer = new byte[8192]; + + int bytesRead; + while((bytesRead = inStream.read(buffer, 0, 8192)) != -1) { + os.write(buffer, 0, bytesRead); + } + } catch (Exception var15) { + var15.printStackTrace(); + } finally { + try { + if (null != os) { + os.close(); + } + + if (null != inStream) { + inStream.close(); + } + } catch (Exception var14) { + var14.printStackTrace(); + } + + } + + return file; + } } -- Gitblit v1.8.0