java 对文件进行二进制解读


import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.Vector;

public class FCLT {

    static byte[] Init(String path) throws IOException {
        point = 0;
        return Files.readAllBytes(Paths.get(path));
    }
    static int point = 0;
    static void fseek(byte[] Stream,int len ,int mode){
        point += len;
    }
    static void fread(byte[] value,int len ,int size ,byte[] Stream){
        for(int i = 0 ;i < size ;i++){
            value[i] = Stream[point];
            point++;
        }
    }
    static int byteToInt(byte[] ve){
        int dd =0;
        for(int i = ve.length-1 ;i >=0  ;i --){
            int c = ((char)(((char)dd & 0x00FF) << 8)) & 0x00FF00;
            dd = c | (ve[i] & 0x00FF);
        }
        return dd;
    }

    public static void ECLTFile(String in ,String out) throws IOException {
        String path = in;;
        byte[] Stream = Init(path);
        byte[] Buffer = new byte[2];
        byte[] v45 = new byte[2];
        byte[] Offset = new byte[4];
        byte[] v38 = new byte[2];
        byte[] v53 = new byte[8];
        byte[] v52 = new byte[0x10];
        byte[] v37 = new byte[4];
        byte[] size =  new byte[2];

        fseek(Stream, 4, 1);
        fread(Buffer, 1, 2, Stream);
        fread(Offset, 1, 4, Stream);
        fread(v38, 1, 2, Stream);
        fread(v45, 1, 2, Stream);
        fseek(Stream,byteToInt(v45), 1);
        fread(v45, 1, 2, Stream);
        fseek(Stream, byteToInt(v45), 1);
        fread(v53, 1, 8, Stream);
        fread(v52, 1, 0x10, Stream);
        fread(v37, 1, 4, Stream);
        fread(v45, 1, 2, Stream);
        fseek(Stream, byteToInt(v45), 1);
        fread(v45, 1, 2, Stream);
        fseek(Stream, byteToInt(v45), 1);
        fread(v45, 1, 2, Stream);//额外加的数据 为了读取到9999
        fread(v53, 1, 8, Stream);
        fread(v45, 1, 2, Stream);
        fseek(Stream, byteToInt(v45), 1);
        fread(v45, 1, 2, Stream);
        fseek(Stream, byteToInt(v45), 1);
        fread(v45, 1, 2, Stream);
        fseek(Stream, byteToInt(v45), 1);
        fread(size, 1, 2, Stream);
        int isize = byteToInt(size);
        byte[] buff = new byte[10000];
        byte[] v31 = new byte[8];
        Vector<String> vetWriteData = new Vector<>();
        for (int i = 0; i <  isize; ++i)
        {
            fread(v45, 1, 2, Stream);
            fread(buff, 1, byteToInt(v45), Stream);
            //System.out.println(new String(buff,0,byteToInt(v45),"UTF-16LE"));
            String key =  new String(buff,0,byteToInt(v45),"UTF-16LE");
            //fseek(Stream, (unsigned __int16)v45, 1);
            fread(v45, 1, 2, Stream);
            fread(buff, 1, byteToInt(v45), Stream);
            int ccc = byteToInt(v45);
            String mi = new String(buff,0,ccc,"UTF-16LE");//文件编码

            //fseek(Stream, (unsigned __int16)v45, 1);
            fread(v45, 1, 2, Stream);
            fseek(Stream, byteToInt(v45), 1);
            fread(v31, 1, 8, Stream);

            //(char) 为了转化为无符号数进行原酸
            int  zzz = (((char)v31[1] & 0x00FF )<< 8 | ((char)v31[0] & 0x00FF));

        }
        Myfile.WriteKeyVectorTxt(out,vetWriteData);
    }
    public static void main(String[] args) throws IOException {

       
    }
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值