How to rename an private file of my application?

Posted by Ungureanu Liviu on Stack Overflow See other posts from Stack Overflow or by Ungureanu Liviu
Published on 2010-03-15T10:37:34Z Indexed on 2010/03/15 10:39 UTC
Read the original article Hit count: 186

Filed under:
|

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!

© Stack Overflow or respective owner

Related posts about android-sdk

Related posts about android