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
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();
}
}