This is a replay file from a game that contains player information.
除非我使用的是HEX编辑器,否则我无法用普通的文本编辑器读取此文件。
我需要在Java中做什么才能读取此文件并转换数据,以便输出可读的文本/字符串?
更具体地说,如果你使用HEX编辑器,从LINE:96 Col:16到LINE 97 Col:7,你会发现这个十六进制数:“78 3b e5 02 01 20 10 01”这是玩家的ID ,但是当我试图从Java或普通文件中读取它时,我得到的只是:“ÿx;å.....”
答案 0 :(得分:0)
此页面向您展示如何使用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));
}
}
答案 1 :(得分:0)