`

android -> 读取assets中的文本文件

 
阅读更多

 

1, 先在 src/main/ 下新建 assets 文件夹(Directory) 并存入 db.txt 文本文件

 

2,

 

try {
    //Return an AssetManager instance for your application's package
    InputStream is = getAssets().open("db.txt");
    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, "UTF-8");

    // Finally stick the string into the text view.
    Log.d("mft",text);
} catch (IOException e) {
    // Should never happen!
    throw new RuntimeException(e);
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics