【发布时间】:2018-10-16 06:15:38
【问题描述】:
我正在尝试使用 echo 等命令将变量写入~/.bash_profile,但我无法将其写入文件。
我尝试了以下,
Runtime run = Runtime.getRuntime();
String line = null;
try {
Process pr = run.exec("echo \"export ANDROID_HOME=/Users/abc/Documents/platform-tool\" >> ~/.bash_profile");
pr.waitFor();
BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
while ((line = buf.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
logger.error("Error occurred when getting adb " + e.getMessage());
} catch (InterruptedException ie) {
logger.error("Error occurred when getting adb " + ie.getMessage());
Thread.currentThread().interrupt();
}
我也尝试给出 ' 而不是 \" 并且只是 echo export 仍然没有写入该文件。 当我尝试打印输出时,它会打印
"export ANDROID_HOME=/Users/abc/Documents/platform-tool" >> ~/.bash_profile
但是文件是空的。
我也尝试过使用 printf 但这又不起作用。这些命令也可以在终端中工作,但在 java 中使用,它不会写入文件。
任何帮助都将不胜感激,如果有其他方法我正在使用,请提出建议
【问题讨论】: