Search code examples
androidfilewriter

Two Files with the same modified time?


I'm writing a unit test where two files are being written with about 512Kb of data. I'm writing to them one after the other. I thought that since they are being written to sequentially, file two would be a few milliseconds greater than file one (my assumption here is that writing 512Kb would take at least 1 millisecond). However, the lastModified() function gives the same time for both. I'm guessing that it means both files were written to under a millisecond, thus the same time for both, but this seems unlikely. What else could cause the two files to have the same modified time?

public void Info_FullLogWrittenToFileOneAndTwo_TestStringInLogOne() {
    DevilLog log = DevilLog.getLogger(appContext, LOG_FILE_NAME, LogFileTest.class.getSimpleName());
    clearAllLogFiles();
    fillLogToMaxSize(LOG_ONE_NAME);
    fillLogToMaxSize(LOG_TWO_NAME);
    ...
}

// in another file...
long logOneModifiedTime = logOne.lastModified();
long logTwoModifiedTime = logTwo.lastModified();

File chosenFile;
if (logOneModifiedTime >= logTwoModifiedTime) // modified time is the same

fillLogToMaxSize is a simple write to a file using FileWriter.

Edit: Hm, writing 512Kb is probably going to be different speeds depending on processor speed, and hard drive write speed. Is it not so far-fetched to think that 512Kb could take less than a millisecond on a core i5 using an SSD?


Solution

  • The issue was millisecond precision as Henry and Michael Burr stated.