How to read a file from src/instrumentTest/resources directory in Android?

和自甴很熟 提交于 2019-11-29 07:38:26

You can use the assets folder of the build type your are testing. If you are testing the debug type (which is the default one):

src/debug/res/assets

And then you access those files with

InputStream raw = context.getAssets().open("filename.ext");
String myJson = new Scanner(raw).useDelimiter("\\A").next();

The trick of using the debug build type prevent your testing resources to be packed in the final apk.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!