How can I determine if the OS is little/big endian in Java?
Asked
Active
Viewed 4,417 times
8
-
Why do you want to do this? Java doesn't care and if you're calling native code can't you use that to figure out what architecture you're on? – Amok Aug 31 '09 at 18:19
-
Want to do this to know OS details – rupa Aug 31 '09 at 18:28
-
Duplicate? http://stackoverflow.com/questions/981549/javas-virtual-machines-endianness – Zed Aug 31 '09 at 18:30
-
@Zed: I think that question is different. It is asking if the VM itself uses big- or little-endian representation internally, not necessarily how to detect what the OS is using. – erickson Aug 31 '09 at 18:52
1 Answers
49
Check whether java.nio.ByteOrder.nativeOrder()
is equal to ByteOrder.LITTLE_ENDIAN
or ByteOrder.BIG_ENDIAN
.

SLaks
- 868,454
- 176
- 1,908
- 1,964
-
3
-
2
-
Much like erickson, +1 - both for the correct answer, and the gumption :) – aperkins Aug 31 '09 at 19:51