Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8707269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:49:43+00:00 2026-06-13T03:49:43+00:00

I have a some application specific file which are stored in a directory in

  • 0

I have a some application specific file which are stored in a directory in internal memory.I want user to be able to rename these files through dialog box.I am using following code to rename a selected file by user:

final File dir = context.getDir(UtilityFuctions.USER_LISTS,
                Context.MODE_PRIVATE);
        final File myFile = new File(dir, filename);

        AlertDialog.Builder fileDialog = new AlertDialog.Builder(context);
        fileDialog.setTitle("Rename file");

        // Set an EditText view to get user input
        final EditText input = new EditText(context);
        input.setText(filename);
        fileDialog.setView(input);
        fileDialog.setPositiveButton("Ok",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        String fileName = input.getText().toString();

                            myFile.renameTo(new File(dir,filename));
                            UtilityFuctions.createToast(context, "file rename successfully", 0);
                        }
                    }
                });
        fileDialog.setNegativeButton("Cancel",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // Canceled.
                        dialog.dismiss();
                    }
                });
        fileDialog.create();
        fileDialog.show();

But the above code is not working and the file is not getting new name.I guess renameTo won’t work for this, it will work only for externalmemory. I have a solution in which I can made a copy of exisiting file with new name and delete the old file but that will consume resources and I dont want to do that.Please help me if I am doing something wrong..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:49:44+00:00Added an answer on June 13, 2026 at 3:49 am

    This should work – the issue you have created is you have TWO variables called filename and fileName.

    I’m pretty sure the basic problem is that you are want this line:

    myFile.renameTo(new File(dir,filename));
    

    to actually read

    myFile.renameTo(new File(dir,fileName));
    

    specifically you want to do the rename with the new returned file name (in the local fileName) as opposed to the original (unchanged) file name stored in filename.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an application that uses settings.settings to store some user specific settings
I have a .desktop file which associates my application (mmxfer) with specific mime types,
In my application,i have some .strings files.And on a button click,which is on my
I have one Spreadsheet file in my Google Drive which i want to sync
I'm working on a Python web application in which I have some small modules
I was hoping to get some advice. I want to create an application which
I have some client-server application. And as one of its part, I need to
I have developed some sms application and I can't figure out how to solve
in my application i have some tinymce editors and the userinput is shown with
In my application I have some link buttons there but when I right click

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.