简体   繁体   中英

How to get relative path of an exe in Java

I have a config class that references a chromedriver.exe file via a String path like so

public static final String CHROMEDRIVER_DIRECTORY = "C:\\Users\\asdf\\Desktop\\Testing\\drivers\\chromedriver.exe";

That code is located in the src folder while the chromedriver.exe is located in a separate drivers folder. The project layout looks something like this.

Testing

  1. src -> constants package -> config
  2. drivers -> chromedriver.exe

How can I edit the string so that it can find the chromedriver without having to type the absolute path? Thanks

试试“drivers\\\\chromedriver.exe”。

Keep your chromedriver.exe in one folder in your current project directory(say win ). Then use

System.getProperty("user.dir") + File.separator + "win" + File.separator + "chromedriver.exe"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM