How to get the android Path string to a file on Assets folder?

前端 未结 4 721
野的像风
野的像风 2020-11-27 03:29

I need to know the string path to a file on assets folder, because I\'m using a map API that needs to receive a string path, and my maps must be stored on a

4条回答
  •  感动是毒
    2020-11-27 03:54

    Have a look at the ReadAsset.java from API samples that come with the SDK.

           try {
            InputStream is = getAssets().open("read_asset.txt");
    
            // We guarantee that the available method returns the total
            // size of the asset...  of course, this does mean that a single
            // asset can't be more than 2 gigs.
            int size = is.available();
    
            // Read the entire asset into a local byte buffer.
            byte[] buffer = new byte[size];
            is.read(buffer);
            is.close();
    
            // Convert the buffer into a string.
            String text = new String(buffer);
    
            // Finally stick the string into the text view.
            TextView tv = (TextView)findViewById(R.id.text);
            tv.setText(text);
        } catch (IOException e) {
            // Should never happen!
            throw new RuntimeException(e);
        }
    

提交回复
热议问题