小编dan*_*ony的帖子

以编程方式将文件从缓存目录移动到SDCard

我正在尝试以编程方式将文件从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)

这两个都不起作用..有

什么建议吗?

storage android caching move

3
推荐指数
1
解决办法
9242
查看次数

标签 统计

android ×1

caching ×1

move ×1

storage ×1