From c1a9eee9c9aa0d3c7592fa75e70243e0297b3a0d Mon Sep 17 00:00:00 2001
From: fhx <308050795@qq.com>
Date: 星期四, 06 四月 2023 10:38:03 +0800
Subject: [PATCH] 1.新增文件工具类

---
 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