Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

On the Mac OS, from what I understand you're suppose to store information in "/Library/Application Support/Your App Name" if the files are to 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 store it to "~/Library/Application Support/Your App Name". Notice the "~" at the front. When you do this, each user will have their own data for the app, and be able to read and write.

In Java, if I do new File("~/Library"), this does not work as expected. It just adds "~/Library" to my current folder. Instead what I'd like it to do is return "Users/myAccount/Library". I understand that it's suggested you store files there.

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

like image 828
Stephane Grenier Avatar asked Dec 07 '22 06:12

Stephane Grenier


1 Answers

Java, in its typical "why use one character when you can use forty" style, lets you access the "~" directory via System.getProperty("user.home").

like image 197
John Kugelman Avatar answered Dec 18 '22 14:12

John Kugelman