读取resource资源目录下文件的方法

常量文件定义:
 
1
public static final String APICLIENT_CERT_P12 = "apiclient_cert.p12";
2
使用资源文件:
1
CloseableHttpClient httpclient = null;
2
try {
3
    KeyStore keyStore = KeyStore.getInstance("PKCS12");
4
    //类加载器
5
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
6
    //以流的形式读取资源文件
7
    InputStream inputStream = classLoader.getResourceAsStream(GlobalConfig.APICLIENT_CERT_P12);
8
    log.info("======apiclient_cert_path===end===");
9
    try {
10
        //装载证书资源文件
11
        keyStore.load(inputStream, partner.toCharArray());
12
    } catch (IOException e) {
13
        log.info("======FileInputStream===IOException:" + e);
14
        e.printStackTrace();
15
        return false;
16
    } finally {
17
        inputStream.close();
18
    }
19
      // 这里也是写密码的
20
    SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, partner.toCharArray())
21
  
22
            .build();
23
    SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[]{"TLSv1"}, null,
24
            SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
25
    httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
26
} catch (Exception e) {
27
    e.printStackTrace();
28
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值