我正在尝试以编程方式将文件从Android内部存储器移动到SD卡中的现有目录.
我试过两种方法.在第一个我使用File.renameTo:
String destName = externalDirPath + File.separatorChar + destFileName;
File originFile = new File(cacheDirPath + File.separatorChar + originalfileName);
originFile.renameTo(new File(destName));
Run Code Online (Sandbox Code Playgroud)
在另一个我使用Runtime.getRuntime():
Process p = Runtime.getRuntime().exec("/system/bin/sh -");
DataOutputStream os = new DataOutputStream(p.getOutputStream());
String command = "cp " + cacheDirPath + "/" + originalfileName+ " " + externalDirPath + "/" + destFileName+ "\n";
os.writeBytes(command);
Run Code Online (Sandbox Code Playgroud)
这两个都不起作用..有
什么建议吗?