-1

I got one image file from Internal Storage, example name of file is name_image_old, i want rename become name_image_new. i have tried use function renameTO() but not working. My code:

  private fun rename(from: File, to: File): Boolean {
        return from.parentFile.exists() && from.exists() && from.renameTo(to)
    }

val currentFile = File("/sdcard/currentFile.txt")
                val newFile = File("/sdcard/newFile.txt")

                if (rename(currentFile, newFile)) {
                    //Success
                    Log.i(TAG, "Success")
                } else {
                    //Fail
                    Log.i(TAG, "Fail")
                }

1 Answers1

-1

xin chào Xuân Đức Nguyễn

renameTO() doesn't work in my environment. The solution is to skip the temporary file method alltogeher, since it doesn't seem to be possible to solve in any reasonable time frame.

so i suggest not use File.renameTo() method in Internal Storage environment. Renaming a file in this environment, can do: - Copy content of the old file to new file. - Delete old file. :)