adsense


Showing posts with label JAVA EXAMPLES GETTING THE FILE SIZE. Show all posts
Showing posts with label JAVA EXAMPLES GETTING THE FILE SIZE. Show all posts

Saturday, 31 October 2015

JAVA EXAMPLES GETTING THE FILE SIZE PAGE 174

COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button



JAVA EXAMPLES GETTING THE FILE SIZE






Java Examples - Getting the File size


Problem Description:
How to get the file size from the server?
Solution:
Following example demonstrates How to get the file size from the server.
import java.net.URL;
import java.net.URLConnection;

public class Main {
   public static void main(String[] argv) 
   throws Exception {
      int size;
      URL url = new URL("http://www.server.com");
      URLConnection conn = url.openConnection();
      size = conn.getContentLength();
      if (size < 0)
      System.out.println("Could not determine file size.");
      else
      System.out.println("The size of file is = "
      +size + "bytes");
      conn.getInputStream().close();
   }
}
Result:
The above code sample will produce the following result.
The size of file is = 16384 bytes