系统类setSecurityManager()方法 (System class setSecurityManager() method)
setSecurityManager() method is available in java.lang package.
setSecurityManager()方法在java.lang包中可用。
In setSecurityManager() method, if the security manager is already installed then in that case the given parameter establish a connection as the current security manager else if the given argument is null then in that case the given parameter couldn’t establish a connection as the current security manager then no action will be performed.
在setSecurityManager()方法中 ,如果已经安装了安全管理器,则在这种情况下,给定参数将建立连接作为当前安全管理器;否则,如果给定参数为null,则给定参数将无法建立连接作为当前安全管理器。当前的安全管理器,则不会执行任何操作。
setSecurityManager() method is a static method so it is accessible with the class name too.
setSecurityManager()方法是静态方法,因此也可以使用类名进行访问。
setSecurityManager() method does not throw any exception.
setSecurityManager()方法不会引发任何异常。
Syntax:
句法:
public static void setSecurityManager(SecurityManager sm);
Parameter(s):
参数:
sm(security manager) – represents the security manager if the security manager couldn’t establish a connection previously for the current application.
sm(安全管理器) –如果安全管理器先前无法为当前应用程序建立连接,则表示安全管理器。
Return value:
返回值:
The return type of this method is void, it does not return anything.
此方法的返回类型为void ,它不返回任何内容。
Example:
例:
// Java program to demonstrate the example of
// setSecurityManager () method of System Class.
import java.lang.*;
public class SetSecurityManagerMethod {
public static void main(String[] args) {
// Creating an instance of SecurityManager
SecurityManager sm = new SecurityManager();
// By using setSecurityManager() method is used to
//set the Security Manager
System.setSecurityManager(sm);
// By using getSecurityManager() method is used
//to get the Security Manager
sm = System.getSecurityManager();
// By using conditional statement to check existence
//of Security Manager existence
if (sm == null)
System.out.println("Security manager couldn’t established");
else
System.out.println("Security manager connection is established");
}
}
Output
输出量
E:\Programs>javac SetSecurityManagerMethod.java
E:\Programs>java SetSecurityManagerMethod
Security manager connection is established
翻译自: https://www.includehelp.com/java/system-class-setsecuritymanager-method-with-example.aspx