Code example for File

Methods: exists, getAbsolutePath, renameTo

0
 
                } catch (IOException e) {
                    Log.e(TAG, e.toString());
                } 
            } else { 
                File oldPrefFile = new File(prefsDirectory(context), oldPrefsFileName
                        + FILE_EXTENSION);
                if (oldPrefFile.exists()) {
                    // Commit any changes left 
                    SharedPreferences.Editor prefs = context.getSharedPreferences(oldPrefsFileName,
                            MODE_PRIVATE).edit();
                    if (prefs != null) {
                        prefs.commit();
                        prefs = null;
                    } 
 
                    isRenamed = oldPrefFile.renameTo(newPrefFile);
 
                    Log.v(TAG, "The prefs file '" + oldPrefFile.getAbsolutePath() + "' was "
                            + (isRenamed ? "" : "not ") + " renamed");
 
                } else { 
 
                    Log.d(TAG, "The prefs file '" + oldPrefFile.getAbsolutePath()
                            + "' was not found"); 
 
                } 
            } 
        }