简体   繁体   中英

java nio - How does Paths.get() finds a folder in the root directory of a project?

I am running below mentioned code in an eclipse project(TestProject). I created this folder(named FilesToBeProcessed) inside project root.

private static Path pathDirectory = java.nio.file.Paths.get("FilesToBeProcessed");

pathDirectory gets resolved to full path = "C:\eclipse\workspace-poc\TestProject\FilesToBeProcessed"

How does it resolves this full path, my class is getting executed from inside a package so its not looking into current directory for folder(FilesToBeProcessed), basically how does it know to look inside "C:\eclipse\workspace-poc\TestProject"?

Relative paths are generally resolved against the current working directory , which is part of the execution environment of a process. How it's set depends on how you start the process:

  • When you start an application from an IDE, the current working directory is set according to the project launch configuration in the IDE. If you haven't changed it, the default is the project directory. For Eclipse concretely, see How do I change the working directory for an Eclipse run configuration?

  • When you start an application from the command line, it's set to the current directory of the shell you are in.

  • When you start a GUI application from a graphical menu or by double-clicking on an icon, the current working directory depends on the system but it's typically the user's home directory, or a subdirectory therein

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM