Search code examples
androidfile-iodata-integrity

How to detect file modification?


I have a stored file containing some data. I want to detect if it has been modified, and then address the issue if necessary.

I thought about controlling for the number of lines in the file, but I am stuck.

Moreover, there is no method to perform this: http://developer.android.com/reference/java/io/File.html.

Any ideas please?


Solution

  • Using an MD5 checksum would be one, very intensive way to do this, however if you compare the timestamps for the "modified date" data in the file, you should be able to efficiently find the files that have been modified.

    This should help you start

    File file = new File(absolute_file_location);
    
    if (file.exists())
    {
      Date lastModified = new Date(file.lastModified());
    }