Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4147223

getContentLength in URLConnection does not work for "file" protocol

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.2.0
    • 1.2.0
    • core-libs
    • None
    • 1.2fcs
    • sparc
    • solaris_2.5.1
    • Not verified

      import java.io.*;
      import java.net.*;

      public class URLbug {
          URL u;
          URLConnection urlc;

          public static void main(String args[]) {
             URLbug ub = new URLbug();
          }

          public URLbug() {
             try{
              int len;
              u = new URL("file:/net/java3d/export/java3d/builds/daily/README");
              urlc = u.openConnection();
              urlc.connect();
              // uncomment to see workaround
              // urlc.getContentType();
              len = urlc.getContentLength();
              if (len<0) {
                  System.out.println(len+"not a valid length");
              } else {
                  System.out.println(len+"bytes");
              }
             } catch (IOException ioe) { ioe.printStackTrace(); }

          }

      }

      This doesn't seem to affect http protocol urls.

            mmcclosksunw Michael Mccloskey (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: