简体   繁体   English

将文件从 SD 卡移动到应用程序内部数据(存储)

[英]Move file from SD card to app internal data (Storage)

Background背景

I need to take the following file and move it to my apps internal storage.我需要获取以下文件并将其移动到我的应用程序内部存储。

mnt/sdcard/downloads mnt/sdcard/下载

I can successfully achieve this by copying the file using the following, then deleting the file from the SD card.我可以通过使用以下内容复制文件,然后从 SD 卡中删除文件来成功实现此目的。

writer = new BufferedWriter(new FileWriter(file));
writer.write(data);
writer.close();

While copying a large file I need double the space (which I don't have).复制大文件时,我需要双倍的空间(我没有)。

Question

Is it possible to "move" a file (changing the directory) opposed to copy delete是否可以“移动”文件(更改目录)而不是复制删除

Other information Looking into the matter I've found:其他信息调查我发现的问题:

public boolean renameTo (File newPath)

doc 文档

Both paths are on the same mount point.两条路径都在同一个挂载点上。 On Android, applications are most likely to hit this restriction when attempting to copy between internal storage and an SD card.在 Android 上,应用程序在尝试在内部存储和 SD 卡之间进行复制时最有可能遇到此限制。 quote taken from here引自这里

I don't know if I can get both paths on the same mount point.我不知道是否可以在同一个挂载点上获得两条路径。

听起来您正在处理非常大的文件,因此您可能会研究某种渐进式缩小/增长另一种类型的操作 - 尽管大概只有在您可以检测到没有足够空间用于完整副本的情况下。

I've tried to do the opposite previously (internal to SD, same thing) the copy then delete process is the only one I found to work.我以前尝试过相反的操作(在 SD 内部,同样的事情)复制然后删除过程是我发现唯一可行的过程。 I guess it makes sense that you cannot just 'rename' since the files are on different physical storage areas (not sure if the same applies to some 'virtual' SD cards on some Android devices).我想你不能只是“重命名”是有道理的,因为文件位于不同的物理存储区域(不确定这是否同样适用于某些 Android 设备上的某些“虚拟”SD 卡)。 If they're on different storage spaces, you cannot just swap out the pointers on the file header.如果它们位于不同的存储空间,则不能只是交换文件头上的指针。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM