United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 4403166 File does not support long paths on WIndows NT
4403166 : File does not support long paths on WIndows NT

Details
Type:
Bug
Submit Date:
2001-01-09
Status:
Resolved
Updated Date:
2005-11-21
Project Name:
JDK
Resolved Date:
2005-01-07
Component:
core-libs
OS:
windows_nt,generic,windows_xp,windows_2000
Sub-Component:
java.io
CPU:
x86,generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
8.1ee,1.1.6,1.3.0,1.4.0_01,1.4.1_02,1.4.2,1.4.2_01
Fixed Versions:
6

Related Reports
Duplicate:
Duplicate:
Duplicate:
Duplicate:
Duplicate:
Relates:
Relates:

Sub Tasks

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

                                    

Comments
EVALUATION

The solution we put into 6.0 and 5.0u6 has problem (regression) when dealing with
a "un-canonicalized" absolute path, as suggested in SDC comment. See #6481955 for
more details.
                                     
2006-10-13
EVALUATION

--
This issue was fixed in mustang at b19, and has been fixed for 5.0u6 as 6182812.
                                     
2005-09-22
WORK AROUND

Name: boT120536			Date: 01/09/2001


Avoid deep directory structures.
======================================================================
                                     
2004-09-08
EVALUATION

We now use the CreateFile API to allow longer path lengths. Each component of the path is still limited to 260 characters. When the path is longer than 260 characters it must be fully qualified.
###@###.### 2002-11-11

Adding long path support to the entire file API is too risky for Mantis. We can fix this in Tiger. It is not clear whether the support would be in java.io.File or the new filesystem API.
###@###.### 2003-04-17
                                     
2003-04-17



Hardware and Software, Engineered to Work Together