read file from assets

前端 未结 18 2231
终归单人心
终归单人心 2020-11-21 22:47
public class Utils {
    public static List getMessages() {
        //File file = new File(\"file:///android_asset/helloworld.txt\");
        AssetMan         


        
18条回答
  •  情歌与酒
    2020-11-21 23:49

    Using Kotlin, you can do the following to read a file from assets in Android:

    try {
        val inputStream:InputStream = assets.open("helloworld.txt")
        val inputString = inputStream.bufferedReader().use{it.readText()}
        Log.d(TAG,inputString)
    } catch (e:Exception){
        Log.d(TAG, e.toString())
    }
    

提交回复
热议问题