我怎样才能在我的Andr​​oid项目中的文件夹的相对路径? [英] How can I get relative path of the folders in my android project?

查看:127
本文介绍了我怎样才能在我的Andr​​oid项目中的文件夹的相对路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用code我怎样才能在我的项目文件夹中的相对路径?

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.

我试图做到这一点在我的课堂延伸 android.app.Activity

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

也许类似的东西来获得资源文件路径

推荐答案

请使用类路径。

ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
URL url = classLoader.getResource("path/to/folder");
File file = new File(url.toURI());
// ...

这篇关于我怎样才能在我的Andr​​oid项目中的文件夹的相对路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆