There is a small problem in the following code that it is unable to find the text file src/main/res/raw/dictionary.txt:
RandomAccessFile ifl = new RandomAccessFile("android.resource://"
+ getPackageName() + "/" + R.raw.dict , "r");
Is there any other way by which the text file can successfully be found and opened? Is there a way if we keep these files in 'assets' folder and then access? Plz suggest.
you can better use InputStream to read text in raw folder file ,
public String readRawFile()
{
StringBuilder builder = new StringBuilder();
InputStream in = getResources().openRawResource(R.raw.yourfile);
try {
int count = 0;
byte[] bytes = new byte[32768];
while ( (count = in.read(bytes,0, 32768)) > 0) {
builder.append(new String(bytes, 0, count));
}
in.close();
} catch (IOException e) {
e.printStackTrace();
}
return builder.toString();
}