From d830fef6a2bc2ab061e6ac2b423c4a49dda3cf21 Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期三, 06 十二月 2023 18:08:26 +0800 Subject: [PATCH] 2023年12月06日18:08:20 --- app/src/main/java/com/hdl/photovoltaic/other/HdlFileLogic.java | 60 +++++++++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 43 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlFileLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlFileLogic.java index 012a181..fc1faff 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlFileLogic.java +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlFileLogic.java @@ -7,6 +7,8 @@ import com.hdl.photovoltaic.HDLApp; import com.hdl.photovoltaic.config.UserConfigManage; +import org.apache.commons.io.FileUtils; + import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.BufferedReader; @@ -117,8 +119,20 @@ * @return 鍏ㄨ矾寰� */ public String getDrivePathFileName(String driverCode, String version) { - String driverFileName = driverCode + "_" + version + ".zip"; - return HdlFileLogic.getInstance().getDriveRootPath() + "/" + driverFileName; + String fileName = driverCode + "_" + version + ".zip"; + return HdlFileLogic.getInstance().getDriveRootPath() + "/" + fileName; + } + + /** + * 鑾峰彇鍥轰欢鍗囩骇鏂囦欢鍏ㄨ矾寰� + * + * @param oid 璇ュ浐浠秓id + * @param version 椹卞姩鐗堟湰 + * @return 鍏ㄨ矾寰� + */ + public String getFirmwarePathFileName(String oid, String version) { + String fileName = oid + "_" + version + ".zip"; + return HdlFileLogic.getInstance().getFirmwareRootPath() + "/" + fileName; } //endregion @@ -324,20 +338,7 @@ return null; } FileInputStream fis = new FileInputStream(f); -// byte[] bytes = new byte[fis.available()]; - byte[] readByte = new byte[1024]; - List<Byte> byteList = new ArrayList<>(); - int len = 0; - while ((len = fis.read(readByte)) != -1) { - for (int i = 0; i < len; i++) { - byteList.add(readByte[i]); - } - } - Byte[] forbByte = byteList.toArray(new Byte[0]); - byte[] bytes = new byte[forbByte.length]; - for (int i = 0; i < forbByte.length; i++) { - bytes[i] = forbByte[i]; - } + byte[] bytes = FileUtils.readFileToByteArray(f); fis.close(); System.out.println("璇诲彇鏂囦欢鎴愬姛===" + filePath); return bytes; @@ -356,7 +357,6 @@ */ public String readFile(String filePath) { try { - byte[] bytes = readFileByte(filePath); if (bytes == null) { return ""; @@ -369,6 +369,32 @@ } /** + * 璇诲彇鏂囦欢 + * + * @param filePath 鍏ㄨ矾寰� + * @return 鏁版嵁 + */ + public FileInputStream fileStream(String filePath) { + try { + if (!isBoolean(filePath)) { + return null; + } + File f = new File(filePath); + if (!f.exists()) { + return null; + } + fileLength = f.length(); + return new FileInputStream(f); + } catch (Exception e1) { + System.out.println("璇诲彇鏂囦欢鏈夊紓甯�===" + e1.getMessage()); + return null; + } + + } + + public static long fileLength = 0; + + /** * 鎸囧畾鍒犻櫎鏂囦欢琛屾暟锛堜粠鍓嶉潰鍒犻櫎璧凤級 * * @param filePath 璺緞 -- Gitblit v1.8.0