Size of a file in a remote machine
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Hari_Sivaram
Posted On:   Monday, February 17, 2003 11:18 PM

I need to get the size of a file in a remote machine. Is there any method in the URL or other classes that allow me to do this without downloading the file?(Urgent)

Re: Size of a file in a remote machine

Posted By:   Anonymous  
Posted On:   Tuesday, February 18, 2003 04:01 AM

You could only get the header of a HttpURLConnection by setting its connection method to "HEAD". This won't download the actual content, just returns the header, which usually (not always!) contains the content length:




URL url = new URL("http://myURL");
URLConnection connection = url.openConnection();

if(connection instanceof HttpURLConnection) {
((HttpURLConnection)connection).setRequestMethod("HEAD");
}

System.out.println("type = " + connection.getContentType());
System.out.println("length = " + connection.getContentLength());

About | Sitemap | Contact