将自己的属性文件放在使用 Android Studio 创建的 android 项目中的何处? [英] Where to put own properties file in an android project created with Android Studio?

查看:23
本文介绍了将自己的属性文件放在使用 Android Studio 创建的 android 项目中的何处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用 Android Studio.我不知道把我自己的属性文件放在哪里,因为项目结构中没有资产文件夹.

I just started to use Android Studio. I don't know where to put my own properties file since there is no assets folder in the project structure.

发布的代码段在 Eclipse 中运行良好,但在 Android Studio 中却没有.

The posted snippet works fine in eclipse, but it doesn't in Android Studio.

代码:

    Properties prop = new Properties();

    try {
        //load a properties file
        prop.load(new FileInputStream("app.properties"));

        //get the property value and print it out
        System.out.println(prop.getProperty("server_address"));

    } catch (IOException ex) {
        ex.printStackTrace();
    }

问题 1:Android Studio (v0.5.8) 中我自己的属性文件放在哪里?

Question 1: Where to put my own properties files in Android Studio (v0.5.8)?

问题 2:我如何访问它们?

推荐答案

默认assets文件夹放在src/main/assets,如果不存在就创建.

By default assets folder is placed in src/main/assets, if it does not exists create it.

然后您可以使用如下方式访问该文件:

Then you can access the file using something like this:

getBaseContext().getAssets().open("app.properties")

您可以在此处找到有关 Gradle Android 项目结构的更多信息.

这篇关于将自己的属性文件放在使用 Android Studio 创建的 android 项目中的何处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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