Free CoreJava Programs Source codes | Examples | Video Tutorials Download

Wednesday, January 21, 2009

Program To Print User name, OS name, User directory

import java.util.Enumeration;

import java.util.Properties;

/**

* Print user name, OS name, user directory of Windows(OS).

*

*

*/

public class SystemProperties {

/**

* displays login username, os and user directory of Windows OS

*/

public static void displayUserOsUserDir() {

try {

// getting system properties

Properties pr = System.getProperties();

/*

* Enumeration en= pr.keys(); while(en.hasMoreElements()) { String

* strTemp=en.nextElement().toString(); System.out.println(strTemp + " : " +

* pr.getProperty(strTemp)); }

*/

System.out.println("user.name = " + pr.get("user.name"));

System.out.println("user.home = " + pr.get("user.home"));

System.out.println("os.name = " + pr.get("os.name"));

} catch (Exception e) {

System.out.println("Error Occured!!");

e.printStackTrace();

}

}

/**

* execution begin from here

*

* @param args

* commandline arguments

*/

public static void main(String[] args) {

displayUserOsUserDir();

}

}

No comments:

Post a Comment

Followers