Java tutorial
//package com.java2s; //License from project: Open Source License import java.io.File; import android.content.Context; import android.util.Log; public class Main { /** * Rename existing file in same directory if target file exists, delete * Code nicked from http://stackoverflow.com/users/325442/mr-bungle * @param context * @param originalFileName * @param newFileName */ private static void rename(Context context, String originalFileName, String newFileName) { File originalFile = context.getFileStreamPath(originalFileName); if (originalFile.exists()) { Log.d("SavingHelper", "renaming " + originalFileName + " size " + originalFile.length() + " to " + newFileName); File newFile = new File(originalFile.getParent(), newFileName); if (newFile.exists()) { context.deleteFile(newFileName); } originalFile.renameTo(newFile); } } }