User Working Directory: XP vs Vista

I have a Java desktop application that I wrote. At run time, I create the folders and files by default specified on the system.

Java.io.files clearly states: By default the classes in the java.io package always resolve relative pathnames against the current user directory. This directory is named by the system property user.dir, and is typically the directory in which the Java virtual machine was invoked. By default the classes in the java.io package always resolve relative pathnames against the current user directory. This directory is named by the system property user.dir, and is typically the directory in which the Java virtual machine was invoked.

In addition, I use IzPack to create installation and create shortcuts.

When I run my application on my computer with XP, after installation I get a shortcut on the desktop, and the specified files and folders are created in the place where Izpack installed the Jar. which is the expected behavior.

But when I test this on a Vista machine, folders and files are created on the desktop! even if the Jar is in the right place (c: \ program files .. etc.).

I want these files to be created in the same folder that the Jar is in, and certainly not on the desktop.

Can someone give me an idea of ​​what is going on here?

+6
source share
1 answer

This is because in Vista / Seven, administrative intervention is required to write to the Program Files folder, so the JVM looks for the next recordable location as a backup: the desktop (or the directory of user documents). You can easily define the user's home directory in a unified manner for all operating systems, although this is much better than just letting the JVM choose a reliable - reasonable location.

Since this is a known error for the JVM on Windows, if this does not help, the check reserve is to check the System Environment USERPROFILE variable which should point to the correct user home folder:

 String userHome = System.getenv("USERPROFILE"); 
+1
source

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


All Articles