Java Server File Size Example
Chapter:
Networking
Last Updated:
09-09-2016 14:29:16 UTC
Program:
/* ............... START ............... */
import java.net.URL;
import java.net.URLConnection;
public class JavaServerFileSize {
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();
}
}
/* ............... END ............... */
Output
The size of file is = 16384 bytes
Tags
Server File Size, Java, Networking