Java: get absolute path of project

后端 未结 2 1863
悲&欢浪女
悲&欢浪女 2021-01-16 03:15

I\'m trying to run a exe file in path outside of the current package. My code.java file that runs it is in

%Workspace_path%\\Project\\src\\main\\java\\com\\u         


        
2条回答
  •  爱一瞬间的悲伤
    2021-01-16 03:56

    Well,in your context,the project root is happen to be the current path

    .

    ,that is where the java.exe start to execute,so a easy way is:

    String exePath="src\\main\\resources\\program.exe";
    File exeFile=new File(".",exePath);
    System.out.println(exeFile.getAbusolutePath());
    ...
    

    I tested this code on Eclipse,It's ok. I think is should work on different ide. Good Luck!

提交回复
热议问题