Reading a simple text file

前端 未结 7 1990
甜味超标
甜味超标 2020-11-22 14:10

I am trying to read a simple text file in my sample Android Application. I am using the below written code for reading the simple text file.

InputStream inpu         


        
相关标签:
7条回答
  • 2020-11-22 14:52

    Place your text file in the /assets directory under the Android project. Use AssetManager class to access it.

    AssetManager am = context.getAssets();
    InputStream is = am.open("test.txt");
    

    Or you can also put the file in the /res/raw directory, where the file will be indexed and is accessible by an id in the R file:

    InputStream is = context.getResources().openRawResource(R.raw.test);
    
    0 讨论(0)
提交回复
热议问题