programming-examples/java/Numerical_Problems/java program to get the file size from the server.java

15 lines
536 B
Java
Raw Normal View History

2019-11-15 12:59:38 +01:00
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();
}
}