From 972daa6f2c0d72d40a74387eb0f04acc09750c11 Mon Sep 17 00:00:00 2001
From: whycrzg <ruanzhigang@whycst.com>
Date: 星期五, 02 四月 2021 17:26:25 +0800
Subject: [PATCH] 修改 文档材料存储路径

---
 src/main/java/com/whyc/util/FileUtils.java |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/whyc/util/FileUtils.java b/src/main/java/com/whyc/util/FileUtils.java
index 61b73ff..7260647 100644
--- a/src/main/java/com/whyc/util/FileUtils.java
+++ b/src/main/java/com/whyc/util/FileUtils.java
@@ -1,8 +1,14 @@
 package com.whyc.util;
 
+import org.springframework.boot.system.ApplicationHome;
+import org.springframework.util.ResourceUtils;
+
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
 
 public class FileUtils {
 
@@ -17,4 +23,46 @@
         out.flush();
         out.close();
     }
+
+    /**
+     * 椤圭洰鍚岀骇璺緞
+     * @return
+     */
+    public static String getFilePath() {
+        ApplicationHome ah = new ApplicationHome(FileUtils.class);
+        File file = ah.getSource();
+//        String projectDir = file.getParentFile().getAbsolutePath();
+        String projectDir = file.getAbsolutePath();
+        String dir = projectDir + File.separator + "upload"+File.separator;
+        System.out.println(dir);
+        return dir;
+    }
+
+
+    /**
+     * 鐢熸垚椤圭洰鍚岀骇璺緞
+     * @return
+     * @throws FileNotFoundException
+     */
+    public static String getProjectPath(){
+        //鑾峰彇璺熺洰褰�
+        File path = null;
+        try {
+            path = new File(ResourceUtils.getURL("classpath:").getPath());
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        }
+        if (!path.exists()) {
+            path = new File("");
+        }
+        //濡傛灉涓婁紶鐩綍涓�/static/images/upload/,鍒欏彲浠ュ涓嬭幏鍙�
+        File upload = new File(path.getAbsolutePath(), "static/upload/");
+        if (!upload.exists()) {
+            upload.mkdirs();
+            //鍦ㄥ紑鍙戞祴璇曟ā寮忔椂锛屽緱鍒板湴鍧�涓猴細{椤圭洰璺熺洰褰晑/target/static/images/upload/
+            //鍦ㄦ墦鎴恓ar姝e紡鍙戝竷鏃讹紝寰楀埌鐨勫湴鍧�涓�:{鍙戝竷jar鍖呯洰褰晑/static/images/upload/
+        }
+        return upload.toString()+File.separator;
+    }
+
 }

--
Gitblit v1.9.1