1

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

Unless I'm using an HEX editor, I cannot literally read this file with a normal text editor.

What do I need to do in Java in order to read this file and convert the data so I can output a readable text/string ?

To be more specific, if you use an HEX editor, from LINE:96 Col:16 to LINE 97 Col: 7 you will find this HEX numbers: "78 3b e5 02 01 20 10 01" which is the player's ID, but when trying to read that from Java or a normal file, all I get is: "ÿx;å....."

Zong
  • 6,160
  • 5
  • 32
  • 46
neilnm
  • 183
  • 1
  • 3
  • 8

2 Answers2

0

This page shows you how to read binary files with java.

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

Here is an example:

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));
  }

}  
pablosaraiva
  • 2,343
  • 1
  • 27
  • 38
0

Check this please: Base64 Encoding in Java

What you need is to encode your file as a Base64 file.

You can find it in apache commons library, Be careful to avoid using proprietary Sun classes

Regards

Community
  • 1
  • 1
gersonZaragocin
  • 1,122
  • 12
  • 20