文件流分步读取(可以结合印象笔记来看)
1.将文件全部读出来,记录一个最大值
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| String file_name = “C:\\Users\\Administrator\\Desktop\\365函数转换\\365函数转换\\HC_170727HK030507_20171025231202.ECD”; File file = new File(file_name); if (!file.exists()) { return; } FileInputStream fis=null; String[] fileArray=file.getName().split(“\\.”); FileOutputStream fos=null; decode256.init();
fos=new FileOutputStream(new File(“C:\\Users\\Administrator\\Desktop\\365函数转换\\365函数转换”,fileArray[0]+“.256”));
fis = new FileInputStream(file); int datLength=fis.available();
byte[] ecgByte = new byte[1200]; while(readLength=fis.read(ecgByte)) != -1){
|
2.这里就是一直对读出的文件进行操作(不要多余最大值)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| for (int i=0; i < readLength;i++) { int ecg_wk32 = decode256.eCGBuild(ecgByte[i] & 0x000000ff); chdt11 = chdt1; chdt22 = chdt2; chdt1 = ecg_wk32 / 65536; chdt2 = ecg_wk32 & 65535; while (jj <= position) { fdatava = index / F2 * F1; jj = (long) Math.floor(fdatava); fdatava = fdatava – jj; BLE1.add((int)(chdt11+Math.floor((chdt1–chdt11)*fdatava))); BLE2.add((int)(chdt22+Math.floor((chdt2–chdt22)*fdatava))); index++; } position++; } ECGCH12=new byte[BLE2.size()*6]; for(int i=0,j=0;j<BLE2.size();j++) { ECGCH12[i]= (byte) (BLE1.get(j)&0xff); ECGCH12[++i]=(byte) ((BLE1.get(j) / 256)&0xff); ECGCH12[++i]= (byte) (BLE2.get(j)&0xff); ECGCH12[++i]= (byte) ((BLE2.get(j)/256)&0xff); kk = BLE2.get(j)- BLE1.get(j)+500; ECGCH12[++i]= (byte) (kk&0xff); ECGCH12[++i]= (byte) ((kk / 256)&0xff); i++; }
|
- 最后写进入流里,只要不关闭,就一直写
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| { fos.write(ECGCH12); BLE2.clear(); BLE1.clear();
}catch (Exception e) { e.printStackTrace(); } finally { if(fis!=null) { try { fis.close(); } catch (IOException e) { e.printStackTrace(); } } if(fos!=null) { try { fos.close(); } catch (Exception e2) { }
} }
|