In Java5, how do I get the full name of the user running the application?
-
03-07-2019 - |
Question
In Java5, is there a way to get the full name of the user that is running the application using only JDK APIs? (I know about JAAS and third-party libraries, but they might not be installed on the target system).
I know about System.getProperty("user.name") but that returns the user ID not user NAME.
Solution
The concept of a user's "full" name is OS dependent so there is not a way to get it using standard Java APIs.
OTHER TIPS
import java.util.Scanner;
...
System.out.println("Please enter your full name: ");
Scanner sc = new Scanner(System.in);
String name = sc.nextLine();
;)
As a side note. In one of my systems we get the System.getProperty("user.name") and with the ID query the USERS table (in an Oracle DB) to get the rest of the needed info.
That's as good as you're going to get I'm afraid.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow