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.
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();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With