Changing the current working directory in Java?

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前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏