I have a words.txt file which I have placed in my res/raw folder. The words in the file are separated by space. I\'m having a hard time writing
To get the words from the file from raw folder try with the following approach
Read the data from raw folder using getResources().openRawResource(R.raw.song);
Then get the inputstream data in a byte array
split the data with space.
Use the following code
InputStream is =getResources().openRawResource(R.raw.song);
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
byte[] myData = baf.toByteArray();
String dataInString = new String(myData);
String[] words = dataInString.split(" ");
Thanks Deepak