我不確定你需要編輯哪些文件,但這應該給你那些你需要做的工具。

我已經給了一些示例代碼 below 來幫助你。 你可以在 OnClick() 中執行這個按鈕。/**

* Runs the shell command.

*

* @param command an array of Strings. command[0] contains the name of the

* shell command. command[1]... contains parameters.

*

* @return the text outputted by the command to stderr or stdout

*/

String runCmd(String[] command, boolean readOutput,

boolean waitForExit) {

ProcessBuilder probuilder = new ProcessBuilder()

. command(command)

. redirectErrorStream(true);

String output ="";

Process process;

//Log.d("MyShellCommand","Executing" + command[0]);

try {

process = probuilder.start();

} catch(IOException e) {

return e.getMessage();

}

if (readOutput) {

InputStream is = process.getInputStream();

InputStreamReader isr = new InputStreamReader(is);

BufferedReader br = new BufferedReader(isr);

String line;

try {

while ((line = br.readLine())!= null) {

//Log.d("MyShellCommand","Read a line:" + line);

output += line +"n";

}

} catch(IOException e) {

output = e.getMessage();

}

}

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐