System.getProperty("os.arch");
It should be available on all platforms, see Java System Properties Guide for more information.
But 64-bit Windows platforms will lie in the JVM if it is a 32-bit JVM. In fact, 64-bit Windows will lie in any 32-bit environmental process to help older 32-bit programs run correctly on a 64-bit OS. Read the MSDN article on WOW64 for more information .
As a result, the WOW64 32-bit JVM call to System.getProperty("os.arch") will return "x86". If you want to get the real architecture of the underlying OS in Windows, use the following logic:
String arch = System.getenv("PROCESSOR_ARCHITECTURE"); String wow64Arch = System.getenv("PROCESSOR_ARCHITEW6432"); String realArch = arch != null && arch.endsWith("64") || wow64Arch != null && wow64Arch.endsWith("64") ? "64" : "32";
See also:
HOWTO: Bitness Process Detection
Why% processor_architecture% always returns x86 instead of AMD64
Determine if the current version of Windows is 32-bit or 64-bit .
ChrisH May 09 '11 at 18:13 2011-05-09 18:13
source share