Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read android system file

Tags:

java

android

I have tried many solutions to read files but no one were working. I need a method to read a system file and show the text in a toast or in a dialog. Of course my app has root permission. I have to show the content of "eoc_status" in a toast after a checkbox click.

For example;

Runtime.getRuntime().exec("/sys/kernel/abb-chargalg/eoc_status").getInputStream(); 

I need to open text files.

like image 256
mascIT Avatar asked Mar 20 '23 02:03

mascIT


1 Answers

Assuming you do have read-access to eoc_status

You are going to want to read it, not exec it. ie use cat or use a FileReader:

Then you will want to do something (put it in your toast) with the returned InputStream.

For example:

    BufferedReader  buffered_reader=null;
    try 
    {
        //InputStream istream = Runtime.getRuntime().exec("cat /sys/kernel/abb-chargalg/eoc_status").getInputStream();
        //InputStreamReader istream_reader = new InputStreamReader(istream);
        //buffered_reader = new BufferedReader(istream_reader);
        buffered_reader = new BufferedReader(new FileReader("/sys/kernel/abb-chargalg/eoc_status"));
        String line;

        while ((line = buffered_reader.readLine()) != null) 
        {
            System.out.println(line);
        }           
    } 
    catch (IOException e) 
    {
        // TODO 
        e.printStackTrace();
    }
    finally 
    {
        try 
        {
            if (buffered_reader != null)
                buffered_reader.close();
        } 
        catch (IOException ex) 
        {
            // TODO 
            ex.printStackTrace();
        }
    }       
like image 122
violet313 Avatar answered Apr 21 '23 05:04

violet313