Using JSON File in Android App Resources

前端 未结 8 1172
盖世英雄少女心
盖世英雄少女心 2020-11-28 21:00

Suppose I have a file with JSON contents in the raw resources folder in my app. How can I read this into the app, so that I can parse the JSON?

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 21:22

    From http://developer.android.com/guide/topics/resources/providing-resources.html:

    raw/
    Arbitrary files to save in their raw form. To open these resources with a raw InputStream, call Resources.openRawResource() with the resource ID, which is R.raw.filename.

    However, if you need access to original file names and file hierarchy, you might consider saving some resources in the assets/ directory (instead of res/raw/). Files in assets/ are not given a resource ID, so you can read them only using AssetManager.

提交回复
热议问题