Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • load text file content from assest folder to textview

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 313
    Comment on it

    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);
        }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: