简体   繁体   中英

Find relative path based on absolute path

In my maven project, i need to address sqlite class which is located in resources/db

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

Example -

ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("db/smartADTool.sqlite").getFile());

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