From 9a697d6a8bc05955b9f7322bc86dc3e920e90e14 Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期四, 06 十一月 2025 18:07:21 +0800
Subject: [PATCH] Merge branch 'wuhuyancao' of http://139.186.142.91:10010/r/productDev/dmvisit into wuhuyancao

---
 keyCabinet-android/app/src/main/java/com/doumee/keyCabinet/utils/update/FileUtil.java |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 59 insertions(+), 0 deletions(-)

diff --git a/keyCabinet-android/app/src/main/java/com/doumee/keyCabinet/utils/update/FileUtil.java b/keyCabinet-android/app/src/main/java/com/doumee/keyCabinet/utils/update/FileUtil.java
index 596cbae..42bd3b6 100644
--- a/keyCabinet-android/app/src/main/java/com/doumee/keyCabinet/utils/update/FileUtil.java
+++ b/keyCabinet-android/app/src/main/java/com/doumee/keyCabinet/utils/update/FileUtil.java
@@ -10,6 +10,9 @@
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
 import java.sql.Timestamp;
 import java.text.DecimalFormat;
 
@@ -236,4 +239,60 @@
 		}
 		return file;
 	}
+
+	public static interface DownLoadCallBack{
+		void sucess();
+		void err(String e);
+	}
+
+	public static void downLoadFile(String filePath,String url,DownLoadCallBack callBack){
+		try {
+			URL u = new URL(url);
+			HttpURLConnection conn = (HttpURLConnection) u.openConnection();
+			conn.setConnectTimeout(10000);
+			int responeCode = conn.getResponseCode();
+			InputStream is;
+			if (responeCode == 200) {
+				is = conn.getInputStream();
+			} else {
+				//杩炴帴澶辫触
+				if(callBack!=null){
+					callBack.err("涓嬭浇鍦板潃閿欒");
+				}
+				return;
+			}
+
+			int fileSize = conn.getContentLength();
+			if (fileSize < 1 || is == null) {
+				//鏂囦欢澶у皬涓嶅
+				if(callBack!=null){
+					callBack.err("鏂囦欢澶у皬涓嶅");
+				}
+				return;
+			} else {
+				//涓嬭浇
+				if (FileUtil.deleteFile(filePath)) {// 鍒犻櫎鍘熸潵鐨勫畨瑁呮枃浠跺啀涓嬭浇
+					FileOutputStream fos = new FileOutputStream(filePath);
+					byte[] bytes = new byte[1024];
+					int len = -1;
+					while ((len = is.read(bytes)) != -1) {
+						fos.write(bytes, 0, len);
+						fos.flush();
+					}
+					//涓嬭浇瀹屾垚
+					if(callBack!=null){
+						callBack.sucess();
+					}
+					is.close();
+					fos.close();
+				}
+			}
+		} catch (Exception e) {
+			//涓嬭浇鎶ラ敊
+			if(callBack!=null){
+				callBack.err(e.getMessage());
+			}
+			e.printStackTrace();
+		}
+	}
 }
\ No newline at end of file

--
Gitblit v1.9.3