mac
2023-12-05 b2d2e6dcf6ec38a2f24721f2bc925d634a6eb78d
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
     * @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   路径