You don't, changing user.dir is not supported in the java platform. You should consider writing your code so it does not depend on the current directory. You could potentially use JNI to accomplish this, but this may cause instabilities in the runtime. You could also create another java instance using Runtime.exec.
If you want to get a resource file, such as an icon, use:
InputStream in = MyClass.class.getResourceAsStream("MyIcon.gif"); The only time you should rely on the location of the current directory is when a user invoke your app at the command line and provides the name of a file to process.
No comments:
Post a Comment