CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2000
    Location
    Indore (MP) INDIA.
    Posts
    356

    Get the File Size ....

    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.
    (*Vipul)() ;

  2. #2
    Join Date
    Jan 2000
    Location
    Canada
    Posts
    249

    Re: Get the File Size ....

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured