java.security.Provider類的getProperty()方法用於在此屬性列表中搜索具有指定鍵的屬性。如果在此屬性列表中找不到該鍵,則將遞歸檢查默認屬性列表及其默認值。如果找不到該屬性,則該方法返回null。
用法:
public String getProperty(String key)
參數:此方法以屬性鍵為參數。
返回值:此方法返回具有指定鍵值的此屬性列表中的值;如果找不到該屬性,則返回null。
下麵是說明getProperty()方法的示例:
示例1:
// Java program to demonstrate
// getProperty() method
import java.security.*;
import java.util.*;
public class GFG1 {
public static void main(String[] argv) throws Exception
{
// Declaring int values
int i = 10;
try {
// creating the object of KeyPairGenerator
KeyPairGenerator sr = KeyPairGenerator.getInstance("DSA", "SUN");
// getting the Provider of the KeyPairGenerator sr
// by using method getProvider()
Provider provider = sr.getProvider();
// Declaring the variable of set<Map> type
Set<Object> set;
// getting unmodifiable Set view of the property entries
set = provider.keySet();
// Creating the object of iterator to iterate set
Iterator iter = set.iterator();
while (i > 0) {
// getting the mapped value in element
// using getProperty() method
String property = provider.getProperty((String)iter.next());
// printing the property of specified key
System.out.println("value is : " + property);
i--;
}
}
catch (NoSuchAlgorithmException e) {
System.out.println("Exception thrown : " + e);
}
}
}
輸出:
value is : SHA1withDSA value is : SHA1withDSA value is : SHA1withDSA value is : Software value is : sun.security.provider.JavaKeyStore$DualFormatJKS value is : SHA value is : sun.security.provider.SHA value is : sun.security.provider.JavaKeyStore$CaseExactJKS value is : Software value is : sun.security.provider.DSA$SHA256withDSA
示例2:
// Java program to demonstrate
// getProperty() method
import java.security.*;
import java.util.*;
public class GFG1 {
public static void main(String[] argv) throws Exception
{
// Declaring int values
int i = 10;
try {
// creating the object of KeyPairGenerator
KeyPairGenerator sr = KeyPairGenerator.getInstance("DSA", "SUN");
// getting the Provider of the KeyPairGenerator sr
// by using method getProvider()
Provider provider = sr.getProvider();
// getting the mapped value in element
// using getProperty() method
System.out.println("Trying to search for unspecified key");
String property = provider.getProperty("geeks");
// printing the property of specified key
System.out.println("value is : " + property);
}
catch (NoSuchAlgorithmException e) {
System.out.println("Exception thrown : " + e);
}
}
}
輸出:
Trying to search for unspecified key value is : null
相關用法
- Java LogManager getProperty()用法及代碼示例
- Java Properties getProperty(key)用法及代碼示例
- Java Properties getProperty(key, defaultValue)用法及代碼示例
- Java Provider get()用法及代碼示例
- Java Provider getName()用法及代碼示例
- Java Provider elements()用法及代碼示例
- Java Provider getInfo()用法及代碼示例
- Java Provider toString()用法及代碼示例
- Java Provider getVersion()用法及代碼示例
- Java Provider entrySet()用法及代碼示例
- Java Provider keys()用法及代碼示例
- Java Provider keySet()用法及代碼示例
- Java Provider values()用法及代碼示例
- Java Provider.Service toString()用法及代碼示例
- Java Provider.Service getProvider()用法及代碼示例
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 Provider getProperty() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。