How do you determine 32 or 64 bit architecture of Windows using Java?
Maybe it 's not the best way, but it works.
All I do is get the "Enviroment Variable" which windows has configured for Program Files x86 folder. I mean Windows x64 have the folder (Program Files x86) and the x86 does not. Because a user can change the Program Files path in Enviroment Variables
, or he/she may make a directory "Program Files (x86)" in C:\, I will not use the detection of the folder but the "Enviroment Path" of "Program Files (x86)" with the variable in windows registry.
public class getSystemInfo {
static void suckOsInfo(){
// Get OS Name (Like: Windows 7, Windows 8, Windows XP, etc.)
String osVersion = System.getProperty("os.name");
System.out.print(osVersion);
String pFilesX86 = System.getenv("ProgramFiles(X86)");
if (pFilesX86 !=(null)){
// Put here the code to execute when Windows x64 are Detected
System.out.println(" 64bit");
}
else{
// Put here the code to execute when Windows x32 are Detected
System.out.println(" 32bit");
}
System.out.println("Now getSystemInfo class will EXIT");
System.exit(0);
}
}