Where to put own properties file in an android project created with Android Studio?

后端 未结 4 1734
别跟我提以往
别跟我提以往 2021-01-01 19:50

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.

The posted snippet

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-01 20:02

    public static String getProperty(String key, Context context) throws IOException {
        try {
        Properties properties = new Properties();
        AssetManager assetManager = context.getAssets();
        InputStream inputStream = assetManager.open("config.properties");
        properties.load(inputStream);
        return properties.getProperty(key);
       }catch (IOException e){
       e.fillInStackTrace();
       }
    return null;
    }
    

    Folder Structure:

    Folder Structure

提交回复
热议问题