我想知道是不是用了:
System.getProperty("user.dir");获取文件夹的绝对路径是最好的方法吗?我希望将我的应用程序传递到其他计算机上,我需要一个完整的证明方法来获得'home‘目录,以便当我需要使用其他文件夹时,只需执行以下操作即可添加到路径中:
String path = System.getProperty("user.dir");
String otherFolder = path + "\\other";发布于 2014-07-12 12:51:45
获取当前用户主目录的方式为
String currentUsersHomeDir = System.getProperty("user.home");并附加路径分隔符
String otherFolder = currentUsersHomeDir + File.separator + "other";系统相关的默认名称分隔符,为方便起见,表示为字符串。此字符串包含单个字符,即separatorChar.
发布于 2014-07-12 12:54:36
"user.dir“是当前工作目录,而不是这里描述的主目录。
http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html
此外,通过使用\\而不是File.separator,您将失去使用/作为文件分隔符的*nix系统的可移植性。
发布于 2018-04-27 17:02:40
获取当前工作directory=user.dir的程序
public class CurrentDirectoryExample {
public static void main(String args[]) {
String current = System.getProperty("user.dir");
System.out.println("Current working directory in Java : " + current);
}
}https://stackoverflow.com/questions/24709769
复制相似问题