凡把自己的属性文件,使用Android Studio中创建的Andr​​oid项目? [英] Where to put own properties file in an android project created with Android Studio?

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

问题描述

我刚开始使用Android工作室。我不知道从哪里把我自己的属性文件,因为在项目结构没有资产的文件夹。

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.

在发布的片段工作在日食很好,但它在Android的Studio不会。

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

code:

    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:
凡把我自己的属性文件中的Andr​​oid工作室(v0.5.8)?

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

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

Question 2: How can I access them?

推荐答案

默认情况下资产的文件夹放在的src / main /资产,如果不存在,它创建

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")

您可以找到有关摇篮Android项目结构这里更多信息

You can find more info about Gradle Android project structure here.

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

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