I had copied a file to my android device. When i check it's last modified date with file.lastModified() it returns the date the file was created which is just now. I want the original date when the file was last modified and not copied. I can see this date in windows explorer with the tag Date modified .The file.lastModified() matches with the Date created Tag of the file. If i could get the last Modified Date i can update the file with another file from server after it has been updated by just checking the date. But with created date it is not possible.
Asked
Active
Viewed 7,277 times
1
-
I'm not familiar with the quirks of Android; do you get a different result from java.nio.file.Files.getLastModifiedTime()? – Jason C Aug 07 '13 at 04:10
-
Is it java.io? the file i am referring here is a file on my sdcard created using File file = new File(Environment.getExternalStorageDirectory(),"test.xml") i cannot use the method you mentioned – nissim_dev Aug 07 '13 at 04:57
-
A bit confused - is your program that calls file.lastModified() running on the Andrioid device? Also is it checking the lastModified() of the file on the device? When you say Windows Explorer shows the Date modified for the file correctly, then are we talking about the file lying on the server? – Prahalad Deshpande Aug 07 '13 at 05:16
-
yes it is running on android device and it is checking the lastModified() of the file on device. windows explorer shows date modified correctly for the file in the device not in the server. but when i use the file.lastmodified() method it returns the date created not the last modified date i can see in windows which is the original modified date – nissim_dev Aug 07 '13 at 05:36
-
@user2049132 No, nio is what I meant, but java.nio.file.* is not in Java 6, only 7. – Jason C Aug 07 '13 at 06:21
1 Answers
2
I got Creation date of a document using apache tika in java
Here is my java code to get creation date of document:
public class tikaExample {
public static void main(String[] args) throws SAXException, TikaException {
InputStream is = null;
try {
is = new BufferedInputStream(new FileInputStream(new File("/home/rahul/Downloads/darknet5.doc")));
Parser parser = new AutoDetectParser();
BodyContentHandler handler = new BodyContentHandler();
Metadata metadata = new Metadata();
parser.parse(is, handler, metadata, new ParseContext());
System.out.println("creation date "+metadata.get(Metadata.CREATION_DATE));
System.out.println("last modify date "+metadata.get(Metadata.LAST_MODIFIED));
} catch (IOException e) {
e.printStackTrace();
}
and output of this code is :
creation date 2002-10-16T05:45:00Z
last modify date 2013-07-01T05:12:00Z
that is creation date and time of file.

Rahul Kulhari
- 1,115
- 1
- 15
- 44
-
i could not find a way to make apache tika work. I added the jar file of apache tika to the java classpath library. What else should i do – nissim_dev Aug 08 '13 at 08:31
-
i am working in ubuntu with eclipse so add tika jar file in java build path. – Rahul Kulhari Aug 08 '13 at 09:15
-
-
could not find class org.apache.tika.parser.Autodetectparser error has occured during the runtime. Eclipse does not show any problem with the code but this occurs during runtime. – nissim_dev Aug 08 '13 at 10:13
-
-
it shows an error ....could not find class org.apache.tika.parser.xml.XMLParser although eclipse asked me to import the exact same class after replacing the code with the XMLParser – nissim_dev Aug 09 '13 at 02:21
-
turns out the tika jar file is 27mb. there is an unable to execute dex error. i have to reduce the jar to only the classes i want now. – nissim_dev Aug 09 '13 at 02:57
-
-
This link of program might help you. [link](https://www.dropbox.com/s/ujnsqebmbaktca2/filecrea.docx) – Rahul Kulhari Aug 09 '13 at 04:39