This little java utility class lets you find the user who is currently logged in (username) to your system.
/**
* @author Kushal Paudyal
* www.sanjaal.com/java
* Last Modified On 2009-06-09
*/
package com.kushal.utils;
/**
* This class demonstrates how to find the current logged in user on the system
* in Java.
*
*/
public class GetCurrentLoggedInUser {
public void getCurrentLoggedInUser() {
String currentLoggedInUser = System.getProperty("user.name");
System.out.println("The Current Logged In User Is: " + currentLoggedInUser);
}
public static void main(String[] args) {
new GetCurrentLoggedInUser().getCurrentLoggedInUser();
}
}
————-
Here is the output when I run this in my machine:
The Current Logged In User Is: kushalp
Originally posted 2009-06-09 15:17:43.