用IO流获取SSL通讯证书的方法,获取内存中File文件内容的方法

public static String KeyInfo() {
    InputStream inputStream = null;
    InputStreamReader isr = null;
    BufferedReader br = null;
    StringBuffer sb = new StringBuffer();
    try {
        File file = new File(Constants.KEYINFO_PATH);
        if (file.exists()) {
            inputStream = new FileInputStream(file);
        } else {
            Log.d("zfr","未读取到文件内容");
            return null;
        }
        //inputStream = assetManager.open("cacert-payplus.ubin.top.pem");
        isr = new InputStreamReader(inputStream);
        br = new BufferedReader(isr);

        sb.append(br.readLine());
        String line = null;
        while ((line = br.readLine()) != null) {
            sb.append("\n" + line);
        }

        br.close();
        isr.close();
        inputStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (br != null) {
                br.close();
            }
            if (isr != null) {
                isr.close();
            }
            if (inputStream != null) {
                inputStream.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //return sb.toString();
    keyInfo = sb.toString();
    //Log.d("zfr_证书===", sb.toString());
    return keyInfo;
}

 

if (SignUtil.KeyInfo() == null) {
    Log.d("zfr", "读取文件失败");
    return null;
}

 

把证书文件放在自己的机器中(目录如下):

 

 

public static final String KEYINFO_PATH = FinancialApplication.mApp.getFilesDir() + File.separator + "config.properties";

注:如有问题可以回复,看到第一时间分析解决,码农不易,感觉对您有用,帮助到您,可否打赏一杯可乐,在此谢过诸位,愿诸君终成大神,前程似锦~~~

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值