I am trying to save some user settings in the home/appdata folder, but when I use dir.canwrite() it returns false. This is the code I use to determine the home/appdata folder:
public static String getAppDataPath() {
if (System.getProperty("os.name").contains("Windows")) {
return System.getenv("APPDATA");
} else {
return getUnixHome();
}
}
public static String getUnixHome() {
String home = System.getProperty("user.home");
return home != null ? home : "~";
}
And this is the code trying to mkdir:
public static boolean checkExistenceDir(String path) {
File dir = new File(path);
if(!dir.exists()) {
dir.mkdir();
}
}
The path in question is:
getAppDataPath() + ".foo" + File.separatorChar
You need the Java process to be started as an Administrator.
You can create a run.vbs script in Windows to start your jar:
To make the program always run as administrator, you need it to run as administrator at least once and update a registry key.