Read android system file

后端 未结 1 891
不知归路
不知归路 2021-01-19 08:09

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 ro

相关标签:
1条回答
  • 2021-01-19 09:02

    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();
            }
        }       
    
    0 讨论(0)
提交回复
热议问题