Android 获取assets的绝对路径

第一种方法:

String path = "file:///android_asset/文件名";

第二种方法:

InputStream abpath = getClass().getResourceAsStream("/assets/文件名");

若要想要转换成String类型

  1. String path = new String(InputStreamToByte(abpath ));
  2. private byte[] InputStreamToByte(InputStream is) throws IOException {
  3. ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
  4. int ch;
  5. while ((ch = is.read()) != -1) {
  6. bytestream.write(ch);
  7. }
  8. byte imgdata[] = bytestream.toByteArray();
  9. bytestream.close();
  10. return imgdata;
  11. }
https://blog.csdn.net/shifuhetudi/article/details/45006605

你可能感兴趣的:(Android 获取assets的绝对路径)