android, How to rename a file?

前端 未结 9 2091
Happy的楠姐
Happy的楠姐 2020-11-28 09:58

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

9条回答
  •  攒了一身酷
    2020-11-28 10:33

    /**
     * ReName any file
     * @param oldName
     * @param newName
     */
    public static void renameFile(String oldName,String newName){
        File dir = Environment.getExternalStorageDirectory();
        if(dir.exists()){
            File from = new File(dir,oldName);
            File to = new File(dir,newName);
             if(from.exists())
                from.renameTo(to);
        }
    }
    

提交回复
热议问题