How to rename a file on sdcard with Android application?

前端 未结 4 1762
暖寄归人
暖寄归人 2020-11-28 10:02

In my Android application, I want to rename the file name at runtime. How can I do it?

This is my code:

String[] command = {\" mv\", \"sun moon.jpg\"         


        
4条回答
  •  無奈伤痛
    2020-11-28 10:52

    I tried adding permissions. Even though it did not work, adding File1.setWritable(true); enabled me to rename the file.

    Below is my code snippet:

    if(from.setWritable(true))
        Log.d("InsertFragmentTwo ", "FileName==> Is Writable");
    File two = new File(sdcard,""+imageCount+"."+s.substring((s.lastIndexOf(".")+1)));
    if (from.renameTo(two)) {
        Log.d("InsertFragmentTwo ", "New FileName==> " + temp);
        imageCount++;
        retrofitImageUpload(temp);
    } else
        Log.d("InsertFragmentTwo ", "File Renaming Failed");
    

提交回复
热议问题