I would like to get the path to the "data.txt" file located in the "raw" folder in "res", on Windows it would be something like "app/res/raw/data", but I can't get it to work.
I have already tried it
String path = "android.resource://" + getPackageName() + "/" + R.raw.datos;
but when I create a File object with the path, its method exists()
returns false and an exception is thrown.
I'd like to save the file as a File object to pass through RandomAccessFile, so I can't eitherInputStream arquivo = getResources().openRawResource(R.raw.datos);
Thanks in advance, regards
There is no path as such, you can actually get
Uri
where the file is located within your directory/raw
:and from this
Uri
get theFile
:You can also get the
InputStream
you can get it byopenRawResource()
:when you get the
InputStream
you can use this method to create a file:This way you can create a file from the
InputStream