Skip to main content

FileOutputStream long path name

2 replies [Last post]
xz7y0s
Offline
Joined: 2005-02-10
Points: 0

I have not been able to get the FileOutputStream to create a file in windows if the path name exceeds about 250 characters. I read the bug fix in Bug ID: 6182812 FileOutputStream constructor throws FileNotFoundException with long file names. I've tried putting the \\?\ in front of my path to no avail. I 've downloaded sdk 1.6 and ran it with and without \\?\ prepended to no avail. I even recompiled it using sdk 1.6 and still it won't work. Has anybody had success doing this? My code is shown below.

private static void writeZipData(File destFile, ZipEntry entry, ZipFile zipFile, int BUFFER) throws IOException
{
// Write the data in the entry in zipFile to file destFile

System.out.println("Extracting: " + entry);
System.out.println("Into: " + destFile);
// grab file's parent directory structure
File destinationParent = destFile.getParentFile();
//System.out.println("destinationParent = " + destinationParent);

// create the parent directory structure if needed
destinationParent.mkdirs();

BufferedInputStream is = new BufferedInputStream(zipFile.getInputStream(entry));

int currentByte;
// establish buffer for writing file
byte data[] = new byte[BUFFER];

// write the current file to disk
FileOutputStream fos = new FileOutputStream("\\\\?\\" + destFile.toString());
BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER);

// read and write until last byte is encountered
while ((currentByte = is.read(data, 0, BUFFER)) != -1)
{
dest.write(data, 0, currentByte);
}
dest.flush();
fos.close();
dest.close();
is.close();
}
My log shows this error:

Extracting: Nextel Communications/Current/Agile Hosting Services-Midrange Hostin
g & Enterprise Server Consolidation Services/Non-Critical Server/OLIVE/2005-01/S
ystem_Availability_Summary_2005-01-01_2005-02-01.pdf
Into: C:\eSLR\eslr_Amer\staging\Amer 20050208 0930\N\Nextel Communications\Curre
nt\Agile Hosting Services-Midrange Hosting & Enterprise Server Consolidation Ser
vices\Non-Critical Server\OLIVE\2005-01\System_Availability_Summary_2005-01-01_2
005-02-01.pdf
Extracting: Nextel Communications/Current/Agile Hosting Services-Midrange Hostin
g & Enterprise Server Consolidation Services/Non-Critical Server/Oracle_Financia
ls/2005-01/System_Availability_Summary_2005-01-01_2005-02-01.pdf
Into: C:\eSLR\eslr_Amer\staging\Amer 20050208 0930\N\Nextel Communications\Curre
nt\Agile Hosting Services-Midrange Hosting & Enterprise Server Consolidation Ser
vices\Non-Critical Server\Oracle_Financials\2005-01\System_Availability_Summary_
2005-01-01_2005-02-01.pdf
java.io.FileNotFoundException: \\?\C:\eSLR\eslr_Amer\staging\Amer 20050208 0930\
N\Nextel Communications\Current\Agile Hosting Services-Midrange Hosting & Enterp
rise Server Consolidation Services\Non-Critical Server\Oracle_Financials\2005-01
\System_Availability_Summary_2005-01-01_2005-02-01.pdf (The filename, directory
name, or volume label syntax is incorrect)
java.io.FileNotFoundException: \\?\C:\eSLR\eslr_Amer\staging\Amer 20050208 0930\
N\Nextel Communications\Current\Agile Hosting Services-Midrange Hosting & Enterp
rise Server Consolidation Services\Non-Critical Server\Oracle_Financials\2005-01
\System_Availability_Summary_2005-01-01_2005-02-01.pdf (The filename, directory
name, or volume label syntax is incorrect)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.(Unknown Source)
at java.io.FileOutputStream.(Unknown Source)
at RenameFiles.writeZipData(RenameFiles.java:948)
at RenameFiles.main(RenameFiles.java:309)

You can see that sometimes it works but not when the path is too long.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mthornton
Offline
Joined: 2003-06-10
Points: 0

You can't prepend \\?\ in front of the path yourself, this is something that has to be done by the Java runtime library (and they have to use the correct Windows methods).
Also see bug 4403166. Allegedly fixed in one of the recent Mustang builds, but I haven't tested it.

xz7y0s
Offline
Joined: 2005-02-10
Points: 0

You are right. I removed the \\?\ and put in the full path name and it's making very long/deep directories as advertised. Thanks for your help