springboot打包jar部署怎么访问外部文件,微信支付证书文件apiclient_cert.p12、微信业务域名、JS接口安全域名、网页授权域名文件的验证

我们在jar部署的时候无法读取外部的文件,或者说很难读取到其他文件。还有就是根目录下无法读取并返回流文件。下面分别以微信支付证书文件和读取并返回微信业务域名、JS接口安全域名、网页授权域名文件的验证为例进行讲解。

1、微信支付证书文件apiclient_cert.p12

比如我们的apiclient_cert.p12在如下目录

linux下:

windows下:

下面直接看程序

public WeConfig() throws Exception {
    	//String path = "C:";//windows下写法
        String path = "/datas/doc***e/mem**duce";//此处为自己实际路径
        String certPath = path+"/apiclient_cert.p12";
        File file = new File(certPath);
        InputStream certStream = new FileInputStream(file);
        this.certData = new byte[(int) file.length()];
        certStream.read(this.certData);
        certStream.close();
    }

这样就可以读取了

2、微信业务域名、JS接口安全域名、网页授权域名文件的验证

@RequestMapping("/{filename}")
        public void zulltest(HttpServletRequest request, HttpServletResponse response, @PathVariable("filename") String fileName) throws Exception{
            String path = "/datas/zb";
            //String path = "C:\\Users\\Administrator\\Desktop";
            String certPath = path+"/"+fileName+".txt";
            File file = new File(certPath);
            FileInputStream fileInputStream = new FileInputStream(file);
            BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(response.getOutputStream());
            byte [] b = new byte[10];
            int i = 0 ;
            while((  i = fileInputStream.read(b)) != -1){
                bufferedOutputStream.write(b,0,i);
            }
            fileInputStream.close();
            bufferedOutputStream.close();
        }

完美运行并访问

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值