Search code examples
androidfilememoryinternal

How to read data from internal storage?


There are a lot of code of how to read internal data storage but, they are usually pointing to how to read files from the internal storage of the application (app package). Well I do not want to read from my files folder of the internal app I want to read this file

/data/system/packages.xml

on routed device I am able to see the content but, my question is how can I read the content of the file on any device (routed or not) from android code.

I want to have some function like this

public String readTheWholeContent(){ return theContent;// of the /data/system/packages.xml file }

what permissions do I need to access the /data/ folder of android phone ?


Solution

  • File pa = new File(Environment.getExternalStorageDirectory() + "file.ext");
            StringBuilder text = new StringBuilder();
            try {
                BufferedReader br = new BufferedReader(new FileReader(pa));
                String line;
                while ((line = br.readLine()) != null) {
                    text.append(line);
                    text.append('\n');
                }
                Log.v("vvv", text.toString());
                return text.toString();
            }
            catch (IOException e) {
    
            }