From f5f9d439cfc6b45acc486ec52ed7a0288e92d189 Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期四, 08 六月 2023 20:34:39 +0800
Subject: [PATCH] 2023年06月08日20:34:33

---
 app/src/main/java/com/hdl/photovoltaic/other/HdlFileLogic.java |   59 +++++++++++++++++++++++++++++++++--------------------------
 1 files changed, 33 insertions(+), 26 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/utils/FileUtils.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlFileLogic.java
similarity index 79%
rename from app/src/main/java/com/hdl/photovoltaic/utils/FileUtils.java
rename to app/src/main/java/com/hdl/photovoltaic/other/HdlFileLogic.java
index 7984262..a4454fe 100644
--- a/app/src/main/java/com/hdl/photovoltaic/utils/FileUtils.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlFileLogic.java
@@ -1,42 +1,53 @@
-package com.hdl.photovoltaic.utils;
+package com.hdl.photovoltaic.other;
 
-import android.content.Context;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.util.Log;
 
-import com.hdl.photovoltaic.other.HdlLogLogic;
+import com.hdl.photovoltaic.HDLApp;
 
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.nio.charset.StandardCharsets;
-import java.util.Objects;
 
+public class HdlFileLogic {
 
-public class FileUtils {
+    private static volatile HdlFileLogic sHdlFileLogic;
+
+    public static synchronized HdlFileLogic getInstance() {
+        if (sHdlFileLogic == null) {
+            synchronized (HdlFileLogic.class) {
+                if (sHdlFileLogic == null) {
+                    sHdlFileLogic = new HdlFileLogic();
+                }
+            }
+
+        }
+        return sHdlFileLogic;
+    }
 
     private static final String TAG = "FileUtils";
 
+    public static final String userId = "";
+
     /**
      * 鑾峰彇鍐呴儴瀛樺偍鏂囦欢璺緞
-     *
-     * @param context 涓婁笅鏂�
-     * @return -
      */
-    public static String getInternalStoreFilesPath(Context context) {
-        if (context == null) {
-            return "";
-        }
-        return context.getFilesDir().getAbsolutePath();
+    private String getInternalStoreFilesPath() {
+        return HDLApp.getInstance().getFilesDir().getAbsolutePath();
     }
 
-    public static File createFile(String dirPath, String fileName) {
+    /**
+     * 鑾峰彇App瀛樻斁鏂囦欢鐨勬牴璺緞
+     */
+    public String getAppFilesPath() {
+        return HDLApp.getInstance().getFilesDir().getAbsolutePath() + userId + "/home";
+    }
+
+    public File createFile(String dirPath, String fileName) {
         try {
             File dirFile = new File(dirPath);
             if (!dirFile.exists()) {
@@ -71,7 +82,7 @@
     /**
      * 鍒涘缓鏂囦欢澶�---涔嬫墍浠ヨ涓�灞傚眰鍒涘缓锛屾槸鍥犱负涓�娆℃�у垱寤哄灞傛枃浠跺す鍙兘浼氬け璐ワ紒
      */
-    public static boolean createFileDir(File dirFile) {
+    public boolean createFileDir(File dirFile) {
         if (dirFile == null) {
             return true;
         }
@@ -92,7 +103,7 @@
         }
     }
 
-    public static void writeFile(String path, String data) {
+    public void writeFile(String path, String data) {
         try {
             File file = new File(path);
             if (!file.exists()) {
@@ -111,7 +122,7 @@
 
     }
 
-    public static String readFile(String filepath) {
+    public String readFile(String filepath) {
         try {
             String fileContent = "";
             if (null == filepath) {
@@ -140,7 +151,7 @@
     /**
      * 鎶婁綅鍥炬暟鎹繚瀛樺埌鎸囧畾璺緞鐨勫浘鐗囨枃浠�
      */
-    public static void writeImage(String path, Bitmap bitmap) {
+    public void writeImage(String path, Bitmap bitmap) {
         try {
             //鏍规嵁鎸囧畾鏂囦欢璺緞鏋勫缓缂撳瓨杈撳嚭娴佸璞�
             BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(path));
@@ -159,7 +170,7 @@
     /**
      * 浠庢寚瀹氳矾寰勭殑鍥剧墖鏂囦欢涓鍙栦綅鍥炬暟鎹�
      */
-    public static Bitmap readImage(String path) {
+    public Bitmap readImage(String path) {
         try {
             //鏍规嵁鎸囧畾鏂囦欢璺緞鏋勫缓缂撳瓨杈撳叆娴佸璞�
             BufferedInputStream bis = new BufferedInputStream(new FileInputStream(path));
@@ -174,8 +185,4 @@
         }
         return null;
     }
-
 }
-
-
-

--
Gitblit v1.8.0