您的位置首页百科问答

android studio怎么读取assets

android studio怎么读取assets

android studio读取assets资源,其实适合eclipse一样的,只需要执行以下代码:

private String[] names={"songhuiqiao.jpg","zhangzetian.jpg","songqian.jpg","hangxiaozhu.jpg","jingtian.jpg"

,"liuyifei.jpg","kangyikun.jpg","dengziqi.jpg"};

声明完之后,就可以读取了,是用下面的代码完成的

//获取Assets目录下的文件

is=context.getClass().getClassLoader().getResourceAsStream("assets/"+names[i]);

下面是我的这边的截图: