android文件重命名,android, How to rename a file?

In my application, I need to record video. Before start of recording in I'm assigning a name and directory to it. After recording is finished user has ability to rename his file. I wrote following code but seem it doesn't work.

When user enters name of file and click on button I'll do this:

private void setFileName(String text) {

String currentFileName = videoURI.substring(videoURI.lastIndexOf("/"), videoURI.length());

currentFileName = currentFileName.substring(1);

Log.i("Current file name", currentFileName);

File directory = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES), MEDIA_NAME);

File from = new File(directory, "currentFileName");

File to = new File(directory, text.trim() + ".mp4");

from.renameTo(to);

Log.i("Directory is", directory.toString());

Log.i("Default path is", videoURI.toString());

Log.i("From path is", from.toString());

Log.i("To path is", to.toString());

}

Text: is the name which is entered by user.

Current Filename: is the name which is assigned by me before recording

MEDIA_NAME: name of folder

Logcat shows this:

05-03 11:56:37.295: I/Current file name(12866): Mania-Karaoke_20120503_115528.mp4

05-03 11:56:37.295: I/Directory is(12866): /mnt/sdcard/Movies/Mania-Karaoke

05-03 11:56:37.295: I/Default path is(12866): /mnt/sdcard/Movies/Mania-Karaoke/Mania-Karaoke_20120503_115528.mp4

05-03 11:56:37.295: I/From path is(12866): /mnt/sdcard/Movies/Mania-Karaoke/currentFileName

05-03 11:56:37.295: I/To path is(12866): /mnt/sdcard/Movies/Mania-Karaoke/hesam.mp4

Any suggestion would be appreciated.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值