Reading a simple text file

前端 未结 7 2023
甜味超标
甜味超标 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:34

    To read the file saved in assets folder

    public static String readFromFile(Context context, String file) {
            try {
                InputStream is = context.getAssets().open(file);
                int size = is.available();
                byte buffer[] = new byte[size];
                is.read(buffer);
                is.close();
                return new String(buffer);
            } catch (Exception e) {
                e.printStackTrace();
                return "" ;
            }
        }
    

提交回复
热议问题