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

File does not support long paths on WIndows NT

    Details

    • Subcomponent:
    • Resolved In Build:
      b19
    • CPU:
      generic, x86
    • OS:
      generic, windows_nt, windows_2000, windows_xp

      Description

      Name: boT120536 Date: 01/09/2001



      ------------
      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      Windows NT with an NTFS file system does not restrict the
      total length of a path (unlike Windows 9x). You can create
      a directory structure where the total path exceeds 255
      characters. Unfortunately Java is unable to use any such file or
      directory. The attached application illustrates this --- it attempts
      to recurse through the structure. On encountering a file or directory
      with path greater than 255 characters it will report that the object
      is neither a file nor a directory. Any attempt to open such a file will also
      fail.

        To avoid this problem the native code should prepend \\?\ before any paths
      which are longer than 255 characters when passing file names to the Windows
      API. Actually you could always do this when the OS is NT.
      7
        To create a deep directory structure try this:
      mkdir deep
      cd deep
      mkdir a
      mkdir a\averylongnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
      mkdir b
      move a b\evenlongernnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
      ren b a
      mkdir b
      move a b\evenlongernnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
      ren b a
      mkdir b
      move a b\evenlongernnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
      ren b a

      repeat the last three lines as required

      -------------------------------------
      import java.io.File;
      import java.io.IOException;

      class RecurseFile
      {
      public static void main(String[] args)
      {
      for (int i=0; i<args.length; i++)
      {
      File f = new File(args[i]);
      System.out.println("Scanning tree: "+f);
      long size = sizeOf(f);
      System.out.println("size="+size);
      }
      }

      private static long sizeOf(File dir)
      {
      String[] names = dir.list();
      if (names == null)
      return 0;
      long size=0;
      for (int i=0; i<names.length; i++)
      {
      File f = new File(dir, names[i]);
      if (f.getPath().length() > 255)
      {
      System.out.println("Long path: "+f);
      }
      if (f.isDirectory())
      {
      size += sizeOf(f);
      }
      else if (f.isFile())
      {
      size += f.length();
      }
      else
      System.out.println("Neither file nor
      directory: "+f);
      }
      return size;
      }
      }
      (Review ID: 114827)
      ###@###.### 10/15/04 20:43 GMT

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                sherman Xueming Shen
                Reporter:
                bonealsunw Bret O'neal (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: