Code example for File

Methods: renameTo

0
    creator.set(0, "ABC");
    creator.set(1, "DE");
    creator.commit();
    cache.close();
 
    assertThat(journalFile.renameTo(journalBkpFile)).isTrue();
    assertThat(journalFile.exists()).isFalse();
 
    cache = DiskLruCache.open(cacheDir, appVersion, 2, Integer.MAX_VALUE);
 
    DiskLruCache.Snapshot snapshot = cache.get("k1");
    assertThat(snapshot.getString(0)).isEqualTo("ABC");
    assertThat(snapshot.getLength(0)).isEqualTo(3);
    assertThat(snapshot.getString(1)).isEqualTo("DE");
    assertThat(snapshot.getLength(1)).isEqualTo(2);
 
    assertThat(journalBkpFile.exists()).isFalse();
    assertThat(journalFile.exists()).isTrue();
  } 
 
  @Test public void journalFileIsPreferredOverBackupFile() throws Exception {