Click to See Complete Forum and Search --> : Get the File Size ....


VipulPathak
September 17th, 2000, 12:53 PM
Hi !

A Simple Question ......

From a Site (Say- www.XYZ.com) how can i get the Size of a File (Say- index.htm) ?

I want to know the Size of index.htm at the site www.xyz.com !!

Thanks ...



-Vipul Pathak.
Pathak Developers Pvt. Ltd.
Indore, (MP) INDIA.


PS: If this helps you then Rate it, so let me know How much is this helpful to you.

weaver
September 17th, 2000, 09:15 PM
import java.io.*;
import java.net.*;

public class FileSizeFromURL {
public static final void main(String[] args) {
URL url;
URLConnection conn;
int size;

if(args.length != 1) {
System.out.println("Usage: FileSizeFromURL ");
return;
}

try {
url = new URL(args[0]);
conn = url.openConnection();
size = conn.getContentLength();
if(size < 0)
System.out.println("Could not determine file size.");
else
System.out.println(args[0] + "\nSize: " + size);
conn.getInputStream().close();
}
catch(Exception e) {
e.printStackTrace();
}
}
}





-------------------------------------------
weaver
icq# 64665116
Please rate this post.
http://weaver.x7.htmlplanet.com