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).
在Java5中,有没有办法只使用JDK API获取运行应用程序的用户的全名? (我了解JAAS和第三方库,但它们可能未安装在目标系统上)。
I know about System.getProperty("user.name") but that returns the user ID not user NAME.
我知道System.getProperty(“user.name”),但返回用户ID而不是用户NAME。
4 个解决方案
#1
The concept of a user's "full" name is OS dependent so there is not a way to get it using standard Java APIs.
用户“完整”名称的概念取决于操作系统,因此无法使用标准Java API获取它。
#2
import java.util.Scanner;
...
System.out.println("Please enter your full name: ");
Scanner sc = new Scanner(System.in);
String name = sc.nextLine();
;)
#3
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.
作为旁注。在我的一个系统中,我们获取System.getProperty(“user.name”)并使用ID查询USERS表(在Oracle DB中)来获取所需的其余信息。
#4
That's as good as you're going to get I'm afraid.
这就像你害怕的那样好。
#1
The concept of a user's "full" name is OS dependent so there is not a way to get it using standard Java APIs.
用户“完整”名称的概念取决于操作系统,因此无法使用标准Java API获取它。
#2
import java.util.Scanner;
...
System.out.println("Please enter your full name: ");
Scanner sc = new Scanner(System.in);
String name = sc.nextLine();
;)
#3
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.
作为旁注。在我的一个系统中,我们获取System.getProperty(“user.name”)并使用ID查询USERS表(在Oracle DB中)来获取所需的其余信息。
#4
That's as good as you're going to get I'm afraid.
这就像你害怕的那样好。