简体   繁体   English

如何在Java中指定相对于某些文件夹的路径?

[英]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 ? 都行不通,我只是不了解路径在Java中的工作方式,我应该指定相对于根文件夹,相对于src文件夹还是相对于什么的路径? 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. 因为我不想使用从C:驱动器开始的完整路径,所以即使我尝试了此操作,它也不起作用。

Is there a way to set a relative folder to specify paths from in java ? 有没有一种方法可以设置相对文件夹来指定java中的路径? I am using Netbeans IDE. 我正在使用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) ./childFolderName:这进入当前文件夹中的子文件夹(。表示当前文件夹)

../folderName : This goes to a folder inside the parent folder ../folderName:这将转到父文件夹内的一个文件夹

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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