0

I want to generate random words with a click of a button in Android Studio with java. I've managed to read .txt file with a click of a button. In this file, there are 2000+ words and it's displaying all at ones. So I want to display single line randomly. Here's my java code:

public void correct_button(View view) {
        String text = "";
        try{
            InputStream is = getAssets().open("words.txt");
            int size = is.available();
            byte[] buffer = new byte[size];
            is.read(buffer);
            is.close();
            text = new String(buffer);
        } catch (IOException ex){
            ex.printStackTrace();
        }
        words.setText(text);
    }

0 Answers0