在内部存储重命名文件重命名、在内部、文件

由网友(心已死去)分享简介:什么是重命名应用程序的内部存储的文件的最好/最简单的方法是什么?我觉得有点怪,有一个 Context.deleteFile()方法,但没有移动或重命名功能。我必须通过保存文件的内容,删除它,创建一个新的,然后将内容复制到一个去所有的方式?或者是有办法的文件在现有文件复制?What's the best/easiest...

什么是重命名应用程序的内部存储的文件的最好/最简单的方法是什么?我觉得有点怪,有一个 Context.deleteFile()方法,但没有移动或重命名功能。我必须通过保存文件的内容,删除它,创建一个新的,然后将内容复制到一个去所有的方式?或者是有办法的文件在现有文件复制?

What's the best/easiest way to rename a file in the application's internal storage? I find it a bit strange that there is a Context.deleteFile() method, but no "move" or "rename" function. Do I have to go all the way through saving the file's contents, deleting it, creating a new one and then copying the contents into that one? Or is there a way to copy a file over an existing file?

更新(2012年8月30日):

Update (Aug. 30, 2012):

按照下面的建议的解决方案,我不能去工作:

As per the suggested solution below, which I cannot get to work:

我有一个名为shoppinglists.csv文件然后,我创建了一个名为shoppinglists.tmp新的文件,并从shoppinglists.csv的内容,一些新的项目复制到。该shoppinglist.tmp文件是则shoppinglists.csv文件的新版本然后我删除旧文件shoppinglists.csv 然后,我需要重命名shoppinglists.tmp文件shoppinglists.csv

我试过这样:

ctx.deleteFile("shoppinglists.csv");           <--- delete the old file
File oldfile = new File("shoppinglists.tmp");
File newfile = new File("shoppinglists.csv");
oldfile.renameTo(newfile);

但是,这是行不通的。 DELETEFILE()之后,仅此而已发生,我留下了新的shoppinglists.tmp文件。

However, this doesn't work. After deleteFile(), nothing more happens, and I'm left with the new shoppinglists.tmp file.

我是什么失踪?

注:有在LogCat中没有任何错误或任何

NB: There are no errors or anything in LogCat.

推荐答案

renameTO()没有在我的环境(Eclipse的靛蓝,AVD与Android版本2.3)工作。解决的办法是alltogeher跳过临时文件的方法,因为它似乎并不可能在任何合理的时间框架来解决

renameTO() doesn't work in my environment (Eclipse Indigo, AVD with android version 2.3). The solution is to skip the temporary file method alltogeher, since it doesn't seem to be possible to solve in any reasonable time frame.

阅读全文

相关推荐

最新文章