0
busybox가있는 기기가 실행 중입니다. 없는 공백와 폴더 또는 파일이 제대로 이동 만 (공백과 폴더 출력은busybox mv (공백 포함)가 자동으로 실패 함
mv -v "/storage/sdcard0/media/music/Progressive Death Metal" "/storage/sdcard0/Music"
없음 MV 출력, 방법은 그냥 "false"를 반환 제대로
public static boolean mv(File source, File target) {
if (!source.exists() || !target.exists()) {
return false;
}
try {
StringBuilder command = new StringBuilder("mv -v ");
command.append('\"');
command.append(source.getCanonicalPath());
command.append('\"');
command.append(' ');
command.append('\"');
command.append(target.getCanonicalPath());
command.append('\"');
System.out.println(command.toString());
Process process = Runtime.getRuntime().exec(command.toString());
StringBuilder output = new StringBuilder();
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
output.append(line);
}
System.out.println(output.toString());
return process.waitFor() == 0;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
를 이동하지 않는 것이 아닌 것 같다 -zero 종료 코드).
정식 경로를 사용해야합니까, 아니면 절대 경로를 사용하여 셸에 그대로 둘 수 있습니까?
편집
나는 또한 파일 이름은 따옴표가 있다면, 인수가 잘못 될 것이라고 와서, 그래서 나는이
같은 이스케이프 문자private static String getCommandLineString(String input) {
return input.replace("\\", "\\\\")
.replace("\"", "\\\"")
.replace("\'", "\\\'")
.replace("`", "\\`")
.replace(" ", "\\ ");
}
그리고 지금 MV 외모를 추가하는 방법을 만들어 내가 무엇을 얻을
public static boolean mv(File source, File target) {
if (!source.exists() || !target.exists()) {
return false;
}
try {
StringBuilder command = new StringBuilder("mv -v ");
command.append(getCommandLineString(source.getAbsolutePath()));
command.append(' ');
command.append(getCommandLineString(target.getAbsolutePath()));
System.out.println(command.toString());
Process process = Runtime.getRuntime().exec(command.toString());
StringBuilder output = new StringBuilder();
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
output.append(line);
}
System.out.println(output.toString());
return process.waitFor() == 0;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
는
입니다하지만 조용한 0이 아닌 종료 코드가 표시됩니다.