我收到错误“java.io.FileNotFoundException:AuthKey_7RHM5B8NS7.p8(没有这样的文件或目录)”,该文件显然在我的目录中,我正在使用该文件的相对路径。这是我的项目目录。
项目目录图片
final ApnsClient apnsClient = new ApnsClientBuilder()
.setApnsServer(ApnsClientBuilder.DEVELOPMENT_APNS_HOST)
.setSigningKey(ApnsSigningKey.loadFromPkcs8File(new File("AuthKey_7RHM5B8NS7.p8"),
"GL87ZNESF6", "7RHM5B8NS7"))
.build();
最佳答案
当您尝试从资源文件夹中获取文件时,您需要为其指定路径。
File file = new File(getClass().getResource("/AuthKey_7RHM5B8NS7.p8").getFile());
或获取 URL
URL res = getClass().getClassLoader().getResource("AuthKey_7RHM5B8NS7.p8");
File file = Paths.get(res.toURI()).toFile();
String absolutePath = file.getAbsolutePath();
关于java - 获取 java.io.FileNotFoundException : FileName (No such file or directory),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56512278/