在String path = properties.getProperty(“PRIVATE”)获取null;

时间:2015-09-01 09:18:38

标签: java digital-signature

这是我的代码。我正在尝试使用数字签名电子令牌签署pdf。

public static String PATH = "C:/Documents and Settings/Administrator/Desktop/New.properties";
    /** Some properties used when signing. */
    public static Properties properties = new Properties();

New.properties文件是:

PUBLIC     C:/Documents and Settings/Administrator/Desktop/public.cer
ROOTCERT    c:/examples/signatures/CACertSigningAuthority.crt
PRIVATE     c:/examples/signatures/private.p12
PASSWORD    123456

但是在代码中我从属性中获取null。 代码在这里:

    String path = properties.getProperty("PRIVATE");
    String keystore_password = properties.getProperty("PASSWORD");
    String key_password = properties.getProperty("PASSWORD");`

我得到路径,keystore_password,key_password null。 那里的错误是什么?

3 个答案:

答案 0 :(得分:1)

您需要按如下方式加载属性文件: -

Properties properties = new Properties();
properties.load(new FileInputStream(YOUR_PATH));

答案 1 :(得分:0)

您必须使用以下方法加载属性文件:

properties.load(new FileInputStream(PATH));

答案 2 :(得分:-2)

只需在属性文件中添加=符号,如: -

PUBLIC = C:/Documents and Settings/Administrator/Desktop/public.cer
ROOTCERT = C:/examples/signatures/CACertSigningAuthority.crt
PRIVATE = C:/examples/signatures/private.p12
PASSWORD = 123456