Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get relative path of the folders in my android project?

How can I get the relative path of the folders in my project using code?

I've created a new folder in my project and I want its relative path so no matter where the app is, the path will be correct.

I'm trying to do it in my class which extends android.app.Activity.

Perhaps something similar to "get file path from asset".

like image 453
Alex Kapustian Avatar asked Apr 23 '10 11:04

Alex Kapustian


People also ask

What is path and relative path?

A relative path refers to a location that is relative to a current directory. Relative paths make use of two special symbols, a dot (.) and a double-dot (..), which translate into the current directory and the parent directory. Double dots are used for moving up in the hierarchy.

Where do Android Studio projects get saved?

Android Studio stores the projects by default in the home folder of the user under AndroidStudioProjects. The main directory contains configuration files for Android Studio and the Gradle build files. The application relevant files are contained in the app folder.


1 Answers

Make use of the classpath.

ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); URL url = classLoader.getResource("path/to/folder"); File file = new File(url.toURI()); // ... 
like image 58
BalusC Avatar answered Oct 14 '22 00:10

BalusC