本文介绍了如何重命名现有文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个文件,文件src =新文件(loc / xyz.mp3)文件dst =新文件(loc /xyz1.mp3)
现在,我要将 dst 重命名为xyz.mp3,同时删除 src 文件。我怎么能做到这一点?
我在尝试,

I have 2 files , File src = new File("loc/xyz.mp3") and File dst=new File("loc/xyz1.mp3")Now , I want to rename dst to xyz.mp3 while delete src file. How can I accomplish this ?I was trying ,

src.delete();
dst.renameTo(src);

我在我的应用程序的后台运行AsyncTask,当我第一次执行它时,它工作正常完美,然而第二次,它崩溃了。请帮忙我该怎么做。

I am running this in AsyncTask in background in my app , when I execute it first time , it works perfectly , however second time , it crashes. Please help how should I go about this.

推荐答案

尝试做:

new File("loc/xyz1.mp3").renameTo(new File("loc/xyz.mp3"));

这应该会自动覆盖原始文件。这个答案来自这里:如何重命名现有文件

This should automatically overwrite the original file. This answer was taken from here: How to rename an existing file

这篇关于如何重命名现有文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 00:27