[英]Find relative path based on absolute path
In my maven
project, i need to address sqlite class which is located in resources/db
在我的maven
项目中,我需要解决位于resources/db
sqlite类
I have a db in the absolute path like: 我在绝对路径中有一个数据库,例如:
C:/Users/Salman/Desktop/Courses/Thesis/Code/ADTool2-master/project/src/main/resources/db/smartADTool.sqlite
and the class file which needs this file is: 需要这个文件的类文件是:
C:/Users/Salman/Desktop/Courses/Thesis/Code/ADTool2-master/project/src/main/java/ee/ut/smarttool/DB/DB.java
to extract the relative path I used the following relative address: 要提取相对路径,我使用了以下相对地址:
../../../../../resources/db/smartADTool.sqlite
but it seems that i the db is not located there. 但似乎我的数据库不在那里。
Since it is in the same project, You can refer it using 由于它在同一个项目中,因此您可以使用
db/smartADTool.sqlite DB / smartADTool.sqlite
Example - 范例-
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("db/smartADTool.sqlite").getFile());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.