From an applet, how do I get information, like size and creation time, about a file on the server?

Brian O'Byrne

Assuming you have access to the file in question through a web server, you can use the URLConnection methods getContentLength() and getLastModified().

URL fileOfInterest = new URL(...);
URLConnection connectionToFileOfInterest =
  fileOfInterest.getConnection();
int contentLength = 
  connectionToFileOfInterest.getContentLength();
long lastModifiedTime =
  connectionToFileOfInterest.getLastModified();
You cannot get the creation time this way.

Warning: this is not reliable across Web servers and you may end up downloading the file completely to get the size.

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact