简体   繁体   中英

How to specify the path relative to some folder in Java?

I am trying to specify the path of an image, and the path of a stylesheet using the following two codes:

pane.getStylesheets().add("src\\dbgui\\Style\\CSS\\base.css");
btn_remove.setStyle("-fx-background-image: url(Style/Images/add.png)")

neither works, i just don't understand how paths works in java, should i specify the path relative to the root folder, or relative to the src folder or relative to what exactly ? because i don't want to use the full path starting by the C: drive, well actually even when i tried this, it didn't work either.

Is there a way to set a relative folder to specify paths from in java ? I am using Netbeans IDE.

path is specified in the below format -: (Assuming current file is located in a particular folder)

../ : This goes one step above the current folder

./childFolderName : This goes into a child folder in the current folder (. refers to current folder)

../folderName : This goes to a folder inside the parent folder

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