How to get user path ~ / Library in Java for Mac OS

On Mac OS, based on what I understand, you should store the information in "/ Library / Application Support / Your App Name" if the files should be read by everyone. However, when it comes to writing, this is an admin-only folder.

Therefore, if you want to write data, you need to save it in "~ / Library / Application Support / Your App Name". Note the "~" in front. When you do this, each user will have their own data for the application and will be able to read and write.

In Java, if I make a new file ("~ / Library"), this does not work properly. It just adds "~ / Library" to my current folder. Instead, I would like it to return "Users / myAccount / Library". I understand that he suggested that you store the files there .

The question is, how to create a File object in Java to point to this folder?

+3
source share
1 answer

Java, in its typical style of “why use a single character when you can use forty”, allows you to access the directory "~"through System.getProperty("user.home").

+12
source

Source: https://habr.com/ru/post/1712054/


All Articles