使用 Java 读取文件

Read file with Java

我想从以下位置读取 java 的 SSL 证书文件:

 URL url = TestSSLPacketChannel.class.getResource("/client.public");
    Path resPath = Paths.get(url.toURI());
    String file = new String(Files.readAllBytes(resPath), "UTF8");

此代码成功找到位于 src\test\resources 的文件,但是当我将文件发送到此 Java 方法时:

new FileInputStream(SSL_Cert);

我得到异常:java.io.FileNotFoundException: Invalid file path

不幸的是我不能改变方法new FileInputStream(SSL_Cert);因为我会破坏代码逻辑。

有什么办法可以解决这个问题吗?

尝试放置整个文件路径。 "C:\User\Folder\file..."