How do relative file paths work in Eclipse?

前端 未结 6 1353
后悔当初
后悔当初 2020-11-29 01:10

So my 2009 new years resolution is to learn Java. I recently acquired \"Java for Dummies\" and have been following along with the demo code in the book by re-writing it usi

6条回答
  •  醉话见心
    2020-11-29 01:47

    A project's build path defines which resources from your source folders are copied to your output folders. Usually this is set to Include all files.

    New run configurations default to using the project directory for the working directory, though this can also be changed.

    This code shows the difference between the working directory, and the location of where the class was loaded from:

    public class TellMeMyWorkingDirectory {
        public static void main(String[] args) {
            System.out.println(new java.io.File("").getAbsolutePath());
            System.out.println(TellMeMyWorkingDirectory.class.getClassLoader().getResource("").getPath());
        }
    }
    

    The output is likely to be something like:

    C:\your\project\directory
    /C:/your/project/directory/bin/
    

提交回复
热议问题