简体   繁体   中英

How to rename video file in android

I try to rename video file with this code:

File from = new File(outputFileName);
            File to = new File(mediaStorageDir,mediaFile);
            from.renameTo(to);

when

outputFileName = //mnt/sdcard/Movies/Your_voice/Your_voice.mp4

and

mediaFile = mediaStorageDir.getPath() + File.separator
                    + "Your_voice" +
                    timeStamp +
                    ".mp4";

and

mediaStorageDir = new File(
                Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES),
                "Your_voice");

no error in locat .... but not execute rename.

I thought this problem cause because this file play in videoview so before the code I add videoView.setVideoPath(""); but it dont help, what I need to do ???

thanks ahead...

You already specify the mediaStorageDir when constructing the File object:

File to = new File(mediaStorageDir,mediaFile);

so you should remove the mediaStorageDir.getPath() from mediaFile , as follows:

mediaFile = "Your_voice" + timeStamp + ".mp4";

You should probably also remove the Your_voice part from the mediaStorageDir, just use:

mediaStorageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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