当我们在本地测试的时候用的是绝对路径或者相对路径,但是项目打包成jar包后,就无法得到这个路径了,这时候我们就需要换一种方式来拿到这个文件
//从classes文件下获取文件
ClassPathResource classPathResource = new ClassPathResource("config/apiclient_key.pem");
//将文件转换为流
InputStream inputStream = classPathResource.getInputStream();
//获取根路径
String property = System.getProperty("user.dir");
//创建一个文件
File targetFile = new File(property+"apiclient_key.pem");
//获取新文件的路径
String path2 = targetFile.getPath();
//将获取的文件拷贝给新的文件
FileUtils.copyInputStreamToFile(inputStream, targetFile);
//调用文件的逻辑
PrivateKey keyPair = getPrivateKey(path2);