What is the best way to find the users home directory in Java?

后端 未结 9 812
清歌不尽
清歌不尽 2020-11-22 09:12

The difficulty is that it should be cross platform. Windows 2000, XP, Vista, OSX, Linux, other unix variants. I am looking for a snippet of code that can accomplish this for

9条回答
  •  甜味超标
    2020-11-22 09:55

    I would use the algorithm detailed in the bug report using System.getenv(String), and fallback to using the user.dir property if none of the environment variables indicated a valid existing directory. This should work cross-platform.

    I think, under Windows, what you are really after is the user's notional "documents" directory.

提交回复
热议问题