Hi,
I would like to write to a file using shell command (eg: ls /data >> test.txt)...
Below is the code snippet I am using.
I am able to execute shell commands using this snippet but unable to write to any file using shell command...
There are other ways to write the file using android built in functions but my requirement is to write to a file through a shell command.
Can anyone please help me out on this...
Code snippet:
I have added the below line to manifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Thanks in advance
I would like to write to a file using shell command (eg: ls /data >> test.txt)...
Below is the code snippet I am using.
I am able to execute shell commands using this snippet but unable to write to any file using shell command...
There are other ways to write the file using android built in functions but my requirement is to write to a file through a shell command.
Can anyone please help me out on this...
Code snippet:
@Override
protected void onStart() {
super.onStart();
Handler handler1 = new Handler();
handler1.postDelayed(new Runnable() {
public void run() {
String cmd = "ls /data >> /sdcard/date.txt";
java.lang.Process p;
try {
p = Runtime.getRuntime().exec(cmd);
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()),cmd.length());
Log.i("AbhiRocks", "Output is " + input.readLine());
} catch (IOException e) {
super.onStart();
Handler handler1 = new Handler();
handler1.postDelayed(new Runnable() {
public void run() {
String cmd = "ls /data >> /sdcard/date.txt";
java.lang.Process p;
try {
p = Runtime.getRuntime().exec(cmd);
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()),cmd.length());
Log.i("AbhiRocks", "Output is " + input.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
}, 5000);
 
}}
}
}, 5000);
 
I have added the below line to manifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Thanks in advance