We can access much machine information in java. Here I am giving some of those.
1. Getting OS current user:
System.getProperty("user.name");
2. Getting OS name:
System.getProperty("os.name");
3. Getting OS arch:
System.getProperty("os.arch");
4. Getting OS version:
System.getProperty("os.version");
5. Getting host name and IP address of machine:
java.net.InetAddress localMachine = java.net.InetAddress.getLocalHost();
localMachine.getHostName();
localMachine.getHostAddress();
6. Getting processor of machine:
System.getenv("PROCESSOR_IDENTIFIER");
7. Getting architecture of processor:
System.getenv("PROCESSOR_ARCHITECTURE");
8. Number of processors:
System.getenv("NUMBER_OF_PROCESSORS");
9. Getting screen dimentions:
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension dim = tk.getScreenSize();
dim.width & dim.height
10. Available drives:
File roots[] = File.listRoots();
for(int i = 0; i < roots.length; i++)
{
System.out.print("Drive : " + roots[i].toString() + " :: Total space : " + roots[i].getTotalSpace() / 1024 / 1024 / 1024 + " GB :: Free space : " + roots[i].getFreeSpace() / 1024 / 1024 / 1024 + " GB");
}//for i
I have tried these things on JDK6.0
No comments:
Post a Comment