Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a File's Last Modified Date

Tags:

I'm using this to see if a file already exists and get its timestamp:

File file = new File(getResources().getString(R.string.file_name));  if (file.exists()) {   Date lastModified = new Date(file.lastModified()); } 

Even though I can see that this file does indeed exist using the Context.fileList() method, the code above always says it doesn't.

How can I get a file's last modified date?

like image 323
Tom Avatar asked Nov 04 '10 23:11

Tom


People also ask

How do I find the last modified date?

Windows file properties You can also see the modified date by viewing the file properties. Right-click the file and select Properties. In the Properties window, the Created date, Modified date, and Accessed date is displayed, similar to the example below.

How do you change the date a file was last modified?

You can manually change the Last Modified Date/Time for a file using a free software called Attribute Changer from http://www.petges.lu/. You will need to remember the modified date/time of your presentation file, modify the file and then use Attribute Changer to set the modified date/time to the previous one.


2 Answers

I take it your problem is that file.exists() fails, the issue with the modified date has nothing to do with it.

I'd venture that the path you're using is local to your application? You'll need to use absolute paths when using File.

like image 92
EboMike Avatar answered Sep 17 '22 00:09

EboMike


Use this for the path

if u send invalid path then u will always get 0 or the 1970 something! (because the Google set The start Date to that date :) )

File file = new File(this.getFilesDir().getAbsolutePath() + "/file1.jpg"); 
like image 41
Mahdi Giveie Avatar answered Sep 19 '22 00:09

Mahdi Giveie