| | |
| | | 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; |
| | |
| | | * @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 该固件oid |
| | | * @param version 驱动版本 |
| | | * @return 全路径 |
| | | */ |
| | | public String getFirmwarePathFileName(String oid, String version) { |
| | | String fileName = oid + "_" + version + ".zip"; |
| | | return HdlFileLogic.getInstance().getFirmwareRootPath() + "/" + fileName; |
| | | } |
| | | |
| | | //endregion |
| | |
| | | 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; |
| | |
| | | */ |
| | | public String readFile(String filePath) { |
| | | try { |
| | | |
| | | byte[] bytes = readFileByte(filePath); |
| | | if (bytes == null) { |
| | | return ""; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 读取文件 |
| | | * |
| | | * @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 路径 |