I have 100 text files in /res/raw folder. I want to read a file named Hello.txt among files from this folder. But the name of the file is stored in a String variable named file_name_gen which gets the name of the file to be accessed from a function defined in code. How can I pass this variable name as file name. Below is my code.
This is what i want to do but this crashes my code abruptly.
//Generate_file() is function that gives a string of filename. Here it is 'Hello'
file_name_gen=Generate_file();
BufferedReader file_reader = new BufferedReader(new InputStreamReader(this.getResources().openRawResource(R.raw.file_name_gen)));
while ((strlines = file_reader.readLine()) != null){
Toast.makeText(this, strlines,Toast.LENGTH_SHORT).show();
}
Any relevant reference or content will help. Thank you in advance.