Check if a user is root in a java application
问题 How can i verify if a user is root in a java application? Thanks 回答1: Process p = Runtime.getRuntime().exec("id -u") Keep in mind that the "root" user on a system may not be called root (although it's rare to change it), and it's also possible to alias it to another username. If the current user is root-like, the output will be 0 . 回答2: Easy. Just use System.getProperty("user.name") 回答3: run a native command? like whoami 回答4: You can call Process p = Runtime.getRuntime.exec("whoami") method.