How to get URI from an asset File?

后端 未结 11 1662
慢半拍i
慢半拍i 2020-11-22 14:27

I have been trying to get the URI path for an asset file.

uri = Uri.fromFile(new File(\"//assets/mydemo.txt\"));

When I check if the file

11条回答
  •  时光说笑
    2020-11-22 14:53

    Yeah you can't access your drive folder from you android phone or emulator because your computer and android are two different OS.I would go for res folder of android because it has good resources management methods. Until and unless you have very good reason to put you file in assets folder. Instead You can do this

    try {
          Resources res = getResources();
          InputStream in_s = res.openRawResource(R.raw.yourfile);
    
          byte[] b = new byte[in_s.available()];
          in_s.read(b);
          String str = new String(b);
        } catch (Exception e) {
          Log.e(LOG_TAG, "File Reading Error", e);
     }
    

提交回复
热议问题