How to rename an private file of my application?
- by Ungureanu Liviu
Hi! I want to rename an context private file created with openFileOutput() but I don't know how...
I tried that:
File file = getFileStreamPath(optionsMenuView.getPlaylistName()); // this file already exists
try {
FileOutputStream outStream = openFileOutput(newPlaylistName, Context.MODE_WORLD_READABLE); // i create a new file with the new name
outStream.close();
}
catch (FileNotFoundException e) {
Log.e(TAG, "file not found!");
e.printStackTrace();
}
catch (IOException e) {
Log.e(TAG, "IO exception");
e.printStackTrace();
}
Log.e(TAG, "rename status: " + file.renameTo(getFileStreamPath(newPlaylistName))); //it return true
This code throw FileNotFoundException but the documentation said "Open a private file associated with this Context's application package for writing. Creates the file if it doesn't already exist." so the new file should be created on disk.
The problem: When I try to read from the new renamed file I got FileNotFoundException!
Thank you!