0
public class intro extends AppCompatActivity {

    private StringBuilder text = new StringBuilder();

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.intro);
        BufferedReader reader = null;

        try {
            reader = new BufferedReader(
                    new InputStreamReader(getAssets().open("assets/Introduction.txt")));

            // do reading, usually loop until end of file reading
            String mLine;
            while ((mLine = reader.readLine()) != null) {
                text.append(mLine);
                text.append('\n');
            }
        } catch (IOException e) {
            Toast.makeText(getApplicationContext(),"Error reading file!", Toast.LENGTH_LONG).show();
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    //log the exception
                }
            }

            TextView output= (TextView) findViewById(R.id.intro);
            output.setText((CharSequence) text);

        }
    }
[This is my project explorer][1]}

I tried lot of paths for opening assets folder but it is showing filenotfound exception. Here I have created Introduction.txt file in Assets folder and written some content on it. But I can't open it by giving path or file name.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245

1 Answers1

1

Remove assets/ from "assets/Introduction.txt". The path supplied to open() is the relative path within your assets/.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491