I was trying to brainstorm on codes how to rename a file in android and I've searched on the net but i didn't see anything. My goal is that when the user press the rename button a dialog box will appear then the user will input the name that user want and it will rename. Guy's please help me about this.. thanks in advance ! :D
Asked
Active
Viewed 4,753 times
-3
-
@PankajKumar: The problem in that question was extraneous quotes. While the titles ask the same question, the underlying problems are different. – icktoofay Jun 21 '13 at 06:14
-
@icktoofay You are right, but the final conclusion is what? Isn't it, he is asking about renaming of file? And if he is asking about the whole functionality then its not possible here to share code for anybody, right? so he should ask one by one or search each functionality one by one :) – Pankaj Kumar Jun 21 '13 at 06:22
-
@PankajKumar: Perhaps this question should be split into smaller questions, but while the answer is contained in the other question, I don't think this should be marked as a duplicate of that one; the question here is “how do I rename files/folders?”, and if it was marked as a duplicate of that one, the answer would be “remove the quotes,” which is not an entirely helpful answer, even if elsewhere the question or answer included the real answer. – icktoofay Jun 21 '13 at 06:27
1 Answers
3
You need to add a permission to your manifest file :
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
And this code :
File sdcard = Environment.getExternalStorageDirectory();
File from = new File(sdcard,"initialName.txt");
File to = new File(sdcard,"finalName.txt");
from.renameTo(to);

marshallino16
- 2,645
- 15
- 29