Android 获取assets的绝对路径

来源:互联网 发布:linux查看阵列卡型号 编辑:程序博客网 时间:2024/05/22 04:39
第一种方法:
       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;

    }



0 0
原创粉丝点击