over 9 years ago
If you want to read some file from assest folder of your project then first you have to get assest folder file named read.txt.
InputStream class is used to read data or content from file, network or from memory, we can also use this input stream with BufferedInputStream to do bulk reads may omit buffering.
Then after reading all bytes from text file we can write contents on any textview like this :
- try {
- InputStream inputStream = getAssets().open("readfilename.txt");
- int size = inputStream.available();
- byte[] buffersBytes = new byte[size];
- inputStream.read(buffersBytes);
- inputStream.close();
- String text = new String(buffersBytes);
- TextView tv = (TextView)findViewById(R.id.text);
- tv.setText(text);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
try { InputStream inputStream = getAssets().open("readfilename.txt"); int size = inputStream.available(); byte[] buffersBytes = new byte[size]; inputStream.read(buffersBytes); inputStream.close(); String text = new String(buffersBytes); TextView tv = (TextView)findViewById(R.id.text); tv.setText(text); } catch (IOException e) { throw new RuntimeException(e); }
Can you help out the community by solving one of the following Digital Marketing problems?
Do activity (Answer, Blog) > Earn Rep Points > Improve Rank > Get more opportunities to work and get paid!
For more topics, questions and answers, please visit the Tech Q&A page.
0 Comment(s)