gpt4 book ai didi

Android Runtime.getRuntime().exec() 通过目录导航

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:52:39 34 4
gpt4 key购买 nike

所以我希望能够编写一个应用程序,它可以打开和显示 logcat 消息、dmesg,并且还能够运行诸如“ls”“cat”“echo”“cd”之类的命令。

如果我执行以下操作:

nativeProc = Runtime.getRuntime().exec("ls\n");
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(nativeProc.getOutputStream()));
BufferedReader in = new BufferedReader(new InputStreamReader(nativeProc.getInputStream()));
String line = null;

while ((line = in.readLine()) != null) {
full = full + "\n" + line;
}

我可以将文本“完整”放入 TextView 并查看根目录。

然而,这就是我所能做的。假设我想找到一个目录,然后更改到它,我遇到了麻烦。

如果我这样做:

nativeProc = Runtime.getRuntime().exec("ls\n");
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(nativeProc.getOutputStream()));
BufferedReader in = new BufferedReader(new InputStreamReader(nativeProc.getInputStream()));
String line = null;

while ((line = in.readLine()) != null) {
full = full + "\n" + line;
}
/* Code here to confirm the existing of a directory*/


nativeProc = Runtime.getRuntime().exec("cd tmp\n");
BufferedReader in2 = new BufferedReader(new InputStreamReader(nativeProc.getInputStream()));
line = null;
String test = "\nStart1:\n";
while ((line = in2.readLine()) != null) {
test = test + "\n" + line;
}

我对“完整”和“文本”都一无所获

有什么想法吗?

最佳答案

您可以使用提供的路径执行 ls,其中应列出文件夹

Runtime.getRuntime().exec(new String[] { "ls", "\\tmp"});

关于Android Runtime.getRuntime().exec() 通过目录导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4618631/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com