0

I have block of hexadecimal data which i want to write in a file as it is.

Block 000100050000470040002E000000000099009900500000000000490067008D0000000000890081007600000000004C002F0027000000000200050000470040002E0000000000000D00590065006C006C006F00770020006F006C0069007600650000000099009900500000000000000D004F006C006900760065002000790065006C006C006F007700000000490067008D0000000000000D00440069007300740061006E007400200062006C00750065000000008900810076000000000000110050006500610072006C0020006D006F00750073006500200067007200650079000000004C002F00270000000000000F004D00610068006F00670061006E0079002000620072006F0077006E0000

Above block represent a Adobe .aco (stores a color palette) file .

Similar File opened in hex editor shows:-

enter image description here

On trying to write Given block using

Code

try {   
    File ACO = new File(f.getAbsolutePath(),"NameRandom.aco");
    ACO.createNewFile();

    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(ACO)));
    try {
        writer.write(<-- Above Block  -->);
    } finally {
        writer.close();
    }
} catch (IOException e) {
    e.printStackTrace();
}

But the above code shows different in hed Editor (as Following image)

enter image description here

I want to write Given block as it is in its current state in file.

Mr_Pouet
  • 4,061
  • 8
  • 36
  • 47
Dilroop Singh
  • 544
  • 6
  • 16

1 Answers1

1

You are getting a different hex code because you are writing the string in some encoding. If you wish to write such byte data first convert the data from string to byte[] and then write the bytes. To convert see: Convert a string representation of a hex dump to a byte array using Java?

Community
  • 1
  • 1