【问题标题】:How would I decode this file?我将如何解码这个文件?
【发布时间】:2013-12-05 06:25:21
【问题描述】:

This is a replay file from a game that contains player information.

除非我使用 HEX 编辑器,否则我无法使用普通文本编辑器逐字阅读此文件。

我需要在 Java 中做什么才能读取此文件并转换数据以便输出可读的文本/字符串?

更具体地说,如果你使用 HEX 编辑器,从 LINE:96 Col:16 到 LINE 97 Col:7 你会发现这个 HEX 数字:“78 3b e5 02 01 20 10 01”,这是玩家的 ID ,但是当试图从 Java 或普通文件中读取它时,我得到的只是:“ÿx;å.....”

【问题讨论】:

    标签: java hex filereader


    【解决方案1】:

    请检查:Base64 Encoding in Java

    您需要将文件编码为 Base64 文件。

    你可以在 apache commons library 中找到它,注意避免使用专有的 Sun 类

    问候

    【讨论】:

      【解决方案2】:

      本页向您展示如何使用 java 读取二进制文件。

      http://www.javapractices.com/topic/TopicAction.do?Id=245

      这是一个例子:

      import java.io.IOException;
      import java.nio.file.Files;
      import java.nio.file.Path;
      import java.nio.file.Paths;
      
      /** JDK 7+. */
      public class SmallBinaryFiles {
      
        public static void main(String... aArgs) throws IOException{
          SmallBinaryFiles binary = new SmallBinaryFiles();
          byte[] bytes = binary.readSmallBinaryFile(FILE_NAME);
          log("Small - size of file read in:" + bytes.length);
          binary.writeSmallBinaryFile(bytes, OUTPUT_FILE_NAME);
        }
      
        final static String FILE_NAME = "C:\\Temp\\cottage.jpg";
        final static String OUTPUT_FILE_NAME = "C:\\Temp\\cottage_output.jpg";
      
        byte[] readSmallBinaryFile(String aFileName) throws IOException {
          Path path = Paths.get(aFileName);
          return Files.readAllBytes(path);
        }
      
        void writeSmallBinaryFile(byte[] aBytes, String aFileName) throws IOException {
          Path path = Paths.get(aFileName);
          Files.write(path, aBytes); //creates, overwrites
        }
      
        private static void log(Object aMsg){
          System.out.println(String.valueOf(aMsg));
        }
      
      }  
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-05-11
        • 1970-01-01
        • 1970-01-01
        • 2020-10-04
        • 2015-05-13
        • 1970-01-01
        • 1970-01-01
        • 2023-03-12
        相关资源
        最近更新 更多