I am trying to create an application in Android. I want to access a file placed in res/raw folder, how can i specify its path while accessing it through File() constructor? And how can I display the file's content using textview?
            Asked
            
        
        
            Active
            
        
            Viewed 1,671 times
        
    0
            
            
        - 
                    2You cannot access it with the File() constructor as it is not actually a file, but an android-unique construct. Please see the documentation at http://developer.android.com/guide/topics/resources/accessing-resources.html – Chris Stratton Apr 03 '14 at 17:54
2 Answers
0
            Use InputStream to read file content.
getResources().getIdentifier("raw/FILENAME_WITHOUT_EXTENSION",
                             "raw", getPackageName());
To get it as a InputStream
InputStream ins = getResources().openRawResource(
            getResources().getIdentifier("raw/FILENAME_WITHOUT_EXTENSION",
            "raw", getPackageName()));
OR
InputStream inputStream = getResources().openRawResource(R.raw.yourresource);
refer http://developer.android.com/guide/topics/resources/providing-resources.html for Providing Resources.
 
    
    
        kaushik parmar
        
- 805
- 6
- 19
- 
                    Yeah! I got it worked by using InputStream inputStream = getResources().openRawResource(R.raw.yourresource); Thank you:) – user3494875 Apr 04 '14 at 14:47
0
            
            
        looks like something like this
InputStream raw = context.getAssets().open("filename.ext");
Reader is = new BufferedReader(new InputStreamReader(raw, "UTF8"));
taken from here: Android how to get access to raw resources that i put in res folder?
Another way I thought you could do it is to use getResources(), and access it via R.raw.fileName
- 
                    Yeah! I got it worked by using InputStream inputStream = getResources().openRawResource(R.raw.yourresource); Thank you:) – user3494875 Apr 04 '14 at 14:47
 
     
    