2009年3月19日木曜日

Java can't get home directory correctly

The user's home directory which is got by Java is different to the real user's home directory in windows xp. When using System.getProperty("user.home") to get home directory in java, you will get the path which contains the desktop folder. So if your desktop is not at the default position, you can't get the real home directory in windows xp. For example, you cut your desktop folder from the default path "C:\Documents and Settings\{user's id}", and paste it to the path "D:\users\{user's id}". Now java's System.getProperty("user.home") will give you the path "D:\users\{user's id}". And if you use System.getenv("USERPROFILE") to get the home directory from envionment variables, you will get the path "C:\Documents and Settings\{user's id}". So when getting home directory by java in windows xp, you must notice which folder is your wanted. I didn't notice it when I tried to get the application data folder. I used System.getProperty("user.home") concating "/Application Data" at first. It worked well in most cases and failed on one computer only because desktop of it is not at the default position. Finally I changed to use System.getenv("AppData") and then everthing is working well.

0 件のコメント:

コメントを投稿