How can I change the current working directory from within a Java program? Everything I've been able to find about the issue claims that you simply can't do it, but I can't believe that that's really the case.
I have a piece of code that opens a file using a hard-coded relative file path from the directory it's normally started in, and I just want to be able to use that code from within a different Java program without having to start it from within a particular directory. It seems like you should just be able to call `System.setProperty( "user.dir", "/path/to/dir" )`, but as far as I can figure out, calling that line just silently fails and does nothing.
I would understand if Java didn't allow you to do this, if it weren't for the fact that it allows you to *get* the current working directory, and even allows you to open files using relative file paths.... Getting and using information is different from changing it. For example on Windows you can easily get environment variables but it is harder to change them (in system wide way).
以上就是Changing the current working directory in Java?的详细内容，更多请关注web前端其它相关文章！