[Android] Android assets目录下资源使用

xiaoxiao2021-02-28  124

第一种方法

String path = "file:///android_assert/文件名"

第二种方法

InputStream abPath = getClass().getResourceAsStream("asserts/文件名");

若想要转换成String类型:

String path = new String (InputStreamToByte(abpath)); private byte[] InputStreamToByte(InputStream is) throws IOException { ByteArrayOutputStream bytesStream = new ByteArrayOutputStream(); int ch; while ((ch = is.read()) != -1) { byteStream.write(ch); } byte[] imgData = byteStream.toByteArray(); byteStream.close(); return imgData; }
转载请注明原文地址: https://www.6miu.com/read-31551.html

最新回复(0)