JDK-4403166 : File does not support long paths on WIndows NT
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version:
    8.1ee,1.1.6,1.3.0,1.4.0_01,1.4.1_02,1.4.2,1.4.2_01 8.1ee,1.1.6,1.3.0,1.4.0_01,1.4.1_02,1.4.2,1.4.2_01
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,windows_nt,windows_2000,windows_xp
  • CPU: generic,x86
  • Submitted: 2001-01-09
  • Updated: 2005-11-21
  • Resolved: 2005-01-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
6 b19Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
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

  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.
  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);
	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();
				System.out.println("Neither file nor
directory: "+f);
		return size;
(Review ID: 114827)
###@###.### 10/15/04 20:43 GMT

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.

EVALUATION -- This issue was fixed in mustang at b19, and has been fixed for 5.0u6 as 6182812.

WORK AROUND Name: boT120536 Date: 01/09/2001 Avoid deep directory structures. ======================================================================

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