0

I want to use a text file in my app and I use this code textview1.set Text(R.raw.ludo); but in the app I only see the path of this file I want to use the text that is in it?

Aminika
  • 113
  • 1
  • 7

2 Answers2

0

The parameter to setText() is a String which is set to it. In your case it is setting it to path of the file in raw folder as that is the value whihc has been assigned to that variable in R.java folder.

If you want to set content, then open the file in your app, read the contents in a string and set that string.

One of the ways to read is:

InputStream inputStream = getResources().openRawResource(R.raw.yourtextfile);
BufferedReader bufferedReader= new BufferedReader(new InputStreamReader(inputStream));
String eachline = bufferedReader.readLine();
while (eachline != null) {
     ........
}
Sushil
  • 7,711
  • 2
  • 31
  • 61
0

you need to read the text from file. Reading this thread can help you : Reading a plain text file in Java

Community
  • 1
  • 1
Leuofiridia
  • 1,124
  • 8
  • 10