datetime - File modified time mismatch on android -
i write current date time file (file may exist or not) content of file. later, compare date modified time of file date time included in file content. however, date modified time less content date time. how can happened later (date modified time of file) have earlier time. data content json string, written text file. (note that: don't set date modified time programmatically)
here code
simpledateformat dateformat = new simpledateformat("mm/dd/yyyy hh:mm:ss"); //this how file content formatted writing. writefile(location, dateformat.format(new date())) public static void writefile(string location, string data) { try { printwriter output = new printwriter( new file(location)); output.write(data); output.close(); } catch (filenotfoundexception e) { } } **to compare** //read content file date date = dateformat.parse(datestring); //get file modified time date disktime = new date(file.lastmodified()); if(this.disktime.gettime() < this.contenttime.gettime() || (this.disktime.gettime() - this.contenttime.gettime()) > 2500) { return false; }
the issue disktime (not always) second before content time above if case returns false.
does happen , how overcome (create file always)?
unfortunately, android lastmodified value has been reported unreliable utilizes internal cache , has bug. can read related answer issue.
and this post author tried similar experiments did. if plan check file modification time, recommend manage timestamp @ data storage sqllite.
Comments
Post a Comment