I need to read the content of a file using a Linux Shell Command executed using Java in Android. What command do I need to execute in order to read all the text in the file and save in a String object?
Note that I can't use the simple Java I/O functions! The file that I need to read is in the device's system directory.
String command= "";
String file_path = "misc/file.txt";
StringBuffer output = new StringBuffer();
Process p;
try {
p = Runtime.getRuntime().exec(command);
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = reader.readLine())!= null) {
output.append(line + "\n");
}
} catch (Exception e) {
e.printStackTrace();
}
String response = output.toString();