Java System.setProperty在我的路径前面添加项目路径

时间:2019-08-02 09:00:55

标签: java

我想将资源文件夹中的文件路径设置为系统属性。

String path = MainCore.class.getClassLoader().getResource("chromedriver-76.0.3809.68.exe").toExternalForm();

System.out.println(path);
//file:/D:/JavaIDEA/projname/target/classes/chromedriver-76.0.3809.68.exe

System.setProperty("webdriver.chrome.driver", path);
//IllegalStateException: The driver executable does not exist: 
//D:\JavaIDEA\projname\file:\D:\JavaIDEA\projname\target\classes\chromedriver-76.0.3809.68.exe

为什么我setProperty会在我的路径前添加项目路径?

我也尝试过这样做:path = path.replace("/", "\\\\");-同样的结果

我正在使用Windows。

1 个答案:

答案 0 :(得分:2)

尝试

debugger;