working-directory

Changing the current working directory in Java?

≯℡__Kan透↙ 提交于 2019-11-25 22:41:42
问题 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

Getting the Current Working Directory in Java

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-25 22:19:23
问题 I want to access my current working directory using String current = new java.io.File( \".\" ).getCanonicalPath(); System.out.println(\"Current dir:\"+current); String currentDir = System.getProperty(\"user.dir\"); System.out.println(\"Current dir using System:\" +currentDir); OutPut: Current dir: C:\\WINDOWS\\system32 Current dir using System: C:\\WINDOWS\\system32 My output is not correct because C drive is not my current directory. Need help in this regard. 回答1: public class