package com.fgkj.bres; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; //FBS9600 内阻数据集 public class RESDataInfo implements FileDataParseInfo_Interface{ public RESDataHead resDataHead; //内阻数据头 public List resDatas; //内阻数据集 public int parse_result = PARSE_RESULT_NULL; public final int file_type = FILE_TYPE_RES; //文件类型 public RESDataInfo() { resDataHead = new RESDataHead(); //内阻数据头 resDatas = new ArrayList<>(); //内阻数据集 } public void readFileData(String filePath) { FileInputStream fis = null; try { File f = new File(filePath); if(!filePath.endsWith(".BRES") && !filePath.endsWith(".bres")) { System.out.println("文件格式错误"); parse_result = PARSE_RESULT_FILETYPEERR; return; } if(!f.exists()) { parse_result = PARSE_RESULT_NOTFOUNDFILE; System.out.println("文件不存在.........."); return; } fis = new FileInputStream(f); byte[] buf = new byte[4]; if(fis.read(buf, 0, buf.length) == RESDataHead.BYTE_LEN) { if(this.resDataHead.setHeadData(buf)) { parse_result = PARSE_RESULT_SUCCESS; }else { parse_result = PARSE_RESULT_FILEERROR; } while(true) { if(resDataHead.checkDataHead(fis)) { byte[] databuf = new byte[RESData.DATABYTE_LEN]; if(fis.read(databuf) == databuf.length) { RESData resData = new RESData(); if(resData.setData(databuf)) { //System.out.println(resData); resDatas.add(resData); } } } if(fis.available() <1) { //System.out.println("解析完成"); break; } } }else { parse_result = PARSE_RESULT_FILEERROR; } } catch (IOException e) { e.printStackTrace(); } finally { if(null != fis) { try { fis.close(); } catch (IOException e) { e.printStackTrace(); } } } } public static void main(String[] args) { RESDataInfo info = new RESDataInfo(); info.readFileData("D:\\桌面文件备份\\公司各种设备资料\\FBS存储文件解析/resdata.bres"); } }