现在的位置: 首页 > 综合 > 正文

Android 获取assets的绝对路径

2018年02月16日 ⁄ 综合 ⁄ 共 494字 ⁄ 字号 评论关闭

 第一种方法:
       String path = "file:///android_asset/文件名";

第二种方法:
    InputStream abpath = getClass().getResourceAsStream("/assets/文件名");

若要想要转换成String类型

String path = new String(InputStreamToByte(abpath ));

    private byte[] InputStreamToByte(InputStream is) throws IOException {
        ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
        int ch;
        while ((ch = is.read()) != -1) {
            bytestream.write(ch);
        }
        byte imgdata[] = bytestream.toByteArray();
        bytestream.close();
        return imgdata;
    }

【上篇】
【下篇】

抱歉!评论已关闭.