0

我一直在 AndroidStudio 中使用这行代码来获取项目中文件的路径:

String srcDir = System.getProperty("user.dir");

目前,当我尝试使用 intelliJ 访问同一个项目时,srcDir返回的值是不同的。有什么解决办法吗?

经历了SO-722003,但这并不能解决我的问题。不能使用SO-12413952,因为项目位置在用户目录之后的不同系统上可能不同。

4

1 回答 1

2

getProperty("user.dir") returns the current working directory. when you start java from command line, it is the directory from which you ran the command. You can use a script or a batch file to set the current working directory to where your project is located.

When you run or debug your project from IntelliJ, it is the directory specified as "Working Directory" in your Run/Debug configuration. See the screenshot below

IntelliJ Run/Debug configuration

You can set it to be the same as the location of your project.

于 2015-12-29T21:14:24.880 回答