YouTip LogoYouTip

Net Serverfile

# Java Example - Get Remote File Size [![Image 3: Java Example](#) Java Example](#) The following example demonstrates how to get the size of a remote file: ## Main.java File import java.net.URL; import java.net.URLConnection; public class Main{public static void main(String[]args)throws Exception{int size; URL url = new URL(""); URLConnection conn = url.openConnection(); size = conn.getContentLength(); if(size<0)System.out.println("Unable to get file size."); else System.out.println("File size: " + size + " bytes"); conn.getInputStream().close(); }} The output of the above code is: File size: 4261 bytes [![Image 4: Java Example](#) Java Example](#)
← Exception FinallyDir Root β†’