Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creation date of file in android

How to get the creation date of file in android. I know about file.lastModified(), but I really need the creation date, that you can see in OS Windows in Properties of file.

If someone know the solution of this task, please, write it below this message. Thanks!

like image 456
Slavik Blase Avatar asked Jul 05 '13 12:07

Slavik Blase


People also ask

How can I tell when an Android file was created?

Android's emulated filesystem does not store the creation date of files or folders, so there is no way to retrieve this data, as it does not exist. (Many thanks to Irfan Latif for confirming this, and to Izzy for clarifications.)

How can you find creation date of a file?

The easiest way to get the file creation date is with the stat command. As we can see, the creation date is shown in the “Birth” field.

How do I change a file creation date?

Right-click the current time and select the option to "Adjust Date/Time." Choose the option to "Change Date and Time..." and input the new information in the time and date fields. Press "OK" to save your changes and then open the file you want to change.

Why is the date a file was modified?

The modified date of a file or folder represents the last time that file or folder was updated.


1 Answers

Creation dates are not supported by every operating system. That's why Java doesn't have a method to get the creation date of a file. I ran into this problem recently also.

What I did was append the timestamp as appendix for the file.

File f = new File("myFile-" + System.currentTimeMillis());

When you later look for your file, you'll be able to extract the appendix and convert it back to a date to find it's creation date.

String fileName = f.getName();
String[] split = fileName.split("-");
long timeStamp = 0;

try {
    timeStamp = Long.parseLong(split[1]);
} catch(NumberFormatException nfe) {
    nfe.printStackTrace();
}

System.out.println("Creation date for file " + f + " is " + new Date(timeStamp));
like image 180
JREN Avatar answered Sep 29 '22 16:09

JREN