如何读取的Java .exe文件的内容 [英] How to read content of .EXE file in Java

查看:557
本文介绍了如何读取的Java .exe文件的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是可能的选择和最appropiate阅读在Java中的可执行文件。

我想产生一个.exe文件的十六进制再presentation。读二进制文件,然后执行转换即时通讯思想。但我怎么能读的。exe?

I want produce the hexadecimal representation of an .exe file. Im thinking of reading the file in binary and then doing the conversion. But how can i read the .exe?

推荐答案

1)读取的字节的文件。用

1) read the file in as bytes. use


   BufferedInputStream( new FileInputStream( new File("bin.exe") ) )

2)转换每个字节十六进制格式。

2) convert each byte to hex format.


    static final String HEXES = "0123456789ABCDEF";
  public static String getHex( byte [] raw ) {
    if ( raw == null ) {
      return null;
    }
    final StringBuilder hex = new StringBuilder( 2 * raw.length );
    for ( final byte b : raw ) {
      hex.append(HEXES.charAt((b & 0xF0) >> 4))
         .append(HEXES.charAt((b & 0x0F)));
    }
    return hex.toString();
  }

这篇关于如何读取的Java .exe文件的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆