I want to Export a ByteBuffer as Little Endian into a file, but when I read in the file again I have to read it as Big Endian to get the right values. How can I export a ByteBuffer in a way that I can read in the created file as Little Endian and get the right values?
//In the ByteBuffer tgxImageData there are the bytes which I want to export and import again, the ByteBuffer is ordered as little endian
//export ByteBuffer into File
FileOutputStream fos = new FileOutputStream(outputfile);
tgxImageData.position(0);
byte[] tgxImageDataByte = new byte[tgxImageData.limit()];
tgxImageData.get(tgxImageDataByte);
fos.write(tgxImageDataByte);
fos.close();
//import File into ByteBuffer
FileInputStream fis2 = new FileInputStream(outputfile);
byte [] arr2 = new byte[(int)outputfile.length()];
fis2.read(arr2);
fis2.close();
ByteBuffer fileData2 = ByteBuffer.wrap(arr2);
fileData2.order(ByteOrder.LITTLE_ENDIAN);
System.out.println(fileData2.getShort(0)); //Wrong output, but here should be right output
fileData2.order(ByteOrder.BIG_ENDIAN);
System.out.println(fileData2.getShort(0)); //Right output, but here should be wrong output