java.io.FileNotFoundException(系统找不到指定的路径)

时间:2012-12-06 10:56:57

标签: java file-io

当我想打开密钥库

时,我收到此异常
java.io.FileNotFoundException: \resources\keystore (The system cannot find the path specified)

基本上我的申请就像

src/
    client.java
    server.java
    resources/
        keystore
        truststore

错误的代码:

System.setProperty("javax.net.ssl.keyStore","/resources/keystore");
System.setProperty("javax.net.ssl.keyStorePassword", "redacted");

我也尝试过./resources/keystore,resources / keystore,\\ resources \\ keystore等。

我的应用程序应该在可执行jar中工作,所以请不要使用绝对路径技术。

3 个答案:

答案 0 :(得分:1)

您可以使用它来获取当前目录路径:

Java代码:

String currentDir = new File(".").getAbsolutePath();

或者这个:

Java代码:

String currentDir = new File(".").getAbsolutePath();

答案 1 :(得分:1)

如果您可以将资源放在CLASS_PATH中,则可以使用

Thread.currentThread().getContextclassLoader().getResource(keystore)

答案 2 :(得分:0)

关于不同的斜杠:使用File.separator代替/,然后它应该在"resources" + File.separator + "keystore"(未经测试)。

相关问题