3

I need to get last modification time of a java resource. When I use

url.openConnection().getLastModified()

it returns the last modification time of the entire jar (same for all items inside), but I need modification time of particular files. The information is there (when I open the jar as a zip, I see the correct time at the particular files). Does someone know how to access it?

Thanks

  • 1
    possible duplicate of [Java: Maintaining zipped files Modified Date](http://stackoverflow.com/questions/10983301/java-maintaining-zipped-files-modified-date) – Peter Lawrey Nov 19 '12 at 10:09
  • [Try this and see if it work for you. ][1] [1]: http://stackoverflow.com/questions/1429172/how-do-i-list-the-files-inside-a-jar-file – Farhan Syed Nov 19 '12 at 10:22

2 Answers2

1

You probably need to query the JAR content, using JarInputStream.
YOu will be iterate over the entries, and get objects of ZipEntry.
One of the accessor methods of ZipEntry is getTime.
I Belive this is the method you're seeking.

Yair Zaslavsky
  • 4,091
  • 4
  • 20
  • 27
0

Try something like:

try (FileSystems jarFS = FileSystems.newFileSystem(URI.create("jar:" + jarURI), Collections.<String, Object>emptyMap())){
    Path resourcePath = jarFS.getPath(resourcePathString); 
    FileTime fileTime = Files.getLastModifiedTime(resourcePath);
}

I also have written soem utility methods to work with Jar files using the NIO File API:

http://softsmithy.sourceforge.net/lib/0.2/docs/api/softsmithy-lib-core/org/softsmithy/lib/nio/file/JarFiles.html

The library is Open Source.

Maven:

<dependency>  
    <groupId>org.softsmithy.lib</groupId>  
    <artifactId>softsmithy-lib-core</artifactId>  
    <version>0.2</version>   
</dependency> 
Puce
  • 37,247
  • 13
  • 80
  • 152