Duplicate :
|
Name: dm26566 Date: 08/10/98 On Windows 95 & NT there seem to be limitations on overall path length for folders and overall path length for files Have not tested UNIX Create single folder: 247 characters in full path specification is the limit 248 characters fails Assumption is that 256 should be the limit Create nested folder: 247 characters in full path specification is the limit 248 characters fails Assumption is that any single folder name should allow <= 256 Create file in single folder: 258 characters in full path specification is the limit 259 characters fails Assumption is that any folder or file name should allow <= 256 Here is the code for TestLength.java /** **/ import java.io.*; import java.util.*; /** TestLength **/ public class TestLength extends Object { protected static String strDrive; protected static String str50; protected static String strA247; protected static String strA248; protected static String strB247; protected static String strB248; protected static String strC212; protected static String strC213; protected static String strFile46; protected static byte[] byteArray; /** **/ public TestLength( ) { // String length ruler // 10 20 30 40 50 // 123456789^123456789^123456789^123456789^123456789^123456789 strDrive = "c:" + File.separator; str50 = "___this_string_happens_to_be_50_characters_long___"; // 3 + 50 + 50 + 50 + 50 + 44 = 247 // strA247 = strDrive + "this_is_1_folder_with_a_247_character_name_length_" + str50 + str50 + str50 + "123456789_123456789_123456789_123456789_1234"; // 3 + 50 + 50 + 50 + 50 + 45 = 248 // strA248 = strDrive + "this_is_1_folder_with_a_248_character_name_length_" + str50 + str50 + str50 + "123456789_123456789_123456789_123456789_12345"; // 3 + 50 + 50 + 50 + 50 + 1 + 43 = 247 // strB247 = strDrive + "this_is_2_folders_with_a_247_character_name_length" + str50 + str50 + str50 + File.separator + "123456789_123456789_123456789_123456789_123"; // 3 + 50 + 50 + 50 + 50 + 1 + 44 = 248 // strB248 = strDrive + "this_is_2_folders_with_a_248_character_name_length" + str50 + str50 + str50 + File.separator + "123456789_123456789_123456789_123456789_1234"; // 3 + 50 + 50 + 50 + 50 + 9 = 212 // strC212 = strDrive + "this_is_1_folder_with_a_212_character_name_length_" + str50 + str50 + str50 + "123456789"; // 3 + 50 + 50 + 50 + 50 + 10 = 213 // strC213 = strDrive + "this_is_1_folder_with_a_213_character_name_length_" + str50 + str50 + str50 + "123456789_"; strFile46 = "this_file_has_a_46_character_name_length.bytes"; // 1K of bytes to write into a file // byteArray = new byte[1024]; Random random = new Random( new Date( ).getTime( ) ); random.nextBytes( byteArray ); } // end Constructor /** getFileObject **/ public File getFileObject( String strName ) { File fileReturn; //System.out.println( "TestLength.getFileObject(), Entering, File name[" + strName + "]" ); try { fileReturn = new File( strName ); System.out.println( "TestLength.getFileObject(), Created file object" ); } catch( Exception e ) { fileReturn = null; System.out.println( "TestLength.getFileObject(), Exception[" + e + "]" ); e.printStackTrace( ); } return fileReturn; } // end getFileObject /** createFolder **/ public boolean createFolder( File file ) { boolean boolReturn = false; try { if ( file == null ) { System.out.println( "TestLength.createFolder(), File object is null" ); return false; } if ( file.exists( ) ) { System.out.println( "TestLength.createFolder(), File object currently exists" ); return false; } boolReturn = file.mkdir( ); } catch( Exception e ) { System.out.println( "TestLength.createFolder(), Exception[" + e + "]" ); e.printStackTrace( ); } return boolReturn; } // end createFolder /** createFolders **/ public boolean createFolders( File file ) { boolean boolReturn = false; try { if ( file == null ) { System.out.println( "TestLength.createFolders(), File object is null" ); return false; } if ( file.exists( ) ) { System.out.println( "TestLength.createFolders(), File object currently exists" ); return false; } boolReturn = file.mkdirs( ); } catch( Exception e ) { System.out.println( "TestLength.createFolders(), Exception[" + e + "]" ); e.printStackTrace( ); } return boolReturn; } // end createFolders /** writeFile **/ public boolean writeFile( String strName ) { boolean boolReturn = false; try { File file = new File( strName ); if ( file.exists( ) ) { System.out.println( "TestLength.writeFile(), File object currently exists" ); return false; } FileOutputStream fos = new FileOutputStream( file ); fos.write( byteArray ); fos.close( ); boolReturn = true; } catch( Exception e ) { System.out.println( "TestLength.writeFile(), Exception[" + e + "]" ); e.printStackTrace( ); } return boolReturn; } // end writeFile /** main **/ public static void main( String args[] ) { File file; boolean boolOK; System.out.println( "TestLength.main(), Entering" ); System.out.println( ); // Setup our static strings // TestLength testLength = new TestLength( ); // Create a single folder with name length of 247 // file = testLength.getFileObject( strA247 ); boolOK = testLength.createFolder( file ); if ( boolOK ) { System.out.println( "TestLength.main(), Created single folder with name length of 247" ); } else { System.out.println( "TestLength.main(), Create single folder with name length of 247 FAILED" ); } System.out.println( ); // Create single folder with name length of 248 // file = testLength.getFileObject( strA248 ); boolOK = testLength.createFolder( file ); if ( boolOK ) { System.out.println( "TestLength.main(), Created single folder with name length of 248" ); } else { System.out.println( "TestLength.main(), Create single folder with name length of 248 FAILED" ); } System.out.println( ); // Create a double folder with name length of 247 // file = testLength.getFileObject( strB247 ); boolOK = testLength.createFolders( file ); if ( boolOK ) { System.out.println( "TestLength.main(), Created double folder with name length of 247" ); } else { System.out.println( "TestLength.main(), Create double folder with name length of 247 FAILED" ); } System.out.println( ); // Create double folder with name length of 248 // file = testLength.getFileObject( strB248 ); boolOK = testLength.createFolders( file ); if ( boolOK ) { System.out.println( "TestLength.main(), Created double folder with name length of 248" ); } else { System.out.println( "TestLength.main(), Create double folder with name length of 248 FAILED" ); } System.out.println( ); // Create a single folder with name length of 212 and then // write out a file with name length of 46 plus separator makes 258 // file = testLength.getFileObject( strC212 ); boolOK = testLength.createFolder( file ); if ( boolOK ) { System.out.println( "TestLength.main(), Created single folder with name length of 212" ); boolOK = testLength.writeFile( strC212 + File.separator + strFile46 ); if ( boolOK ) { System.out.println( "TestLength.main(), Wrote file with name length of 46 into folder with name length of 212 with separator makes 258" ); } else { System.out.println( "TestLength.main(), Write file with name length of 46 into folder with name length of 212 with separator makes 258 FAILED" ); } } else { System.out.println( "TestLength.main(), Create single folder with name length of 212 FAILED" ); } System.out.println( ); // Create a single folder with name length of 213 and then // write out a file with name length of 46 plus separator makes 259 // file = testLength.getFileObject( strC213 ); boolOK = testLength.createFolder( file ); if ( boolOK ) { System.out.println( "TestLength.main(), Created single folder with name length of 213" ); boolOK = testLength.writeFile( strC213 + File.separator + strFile46 ); if ( boolOK ) { System.out.println( "TestLength.main(), Wrote file with name length of 46 into folder with name length of 213 with separator makes 259" ); } else { System.out.println( "TestLength.main(), Write file with name length of 46 into folder with name length of 213 with separator makes 259 FAILED" ); } } else { System.out.println( "TestLength.main(), Create single folder with name length of 213 FAILED" ); } System.out.println( ); System.out.println( "TestLength.main(), Leaving" ); } // end main } // end Class ---------------------------------------------------------------------------------- [dalem@eng]: All tests work on Solaris 2.6 with 1.1.6 and 1.2beta4. Here are the results when running on NT 4.0 with 1.1.6 and 1.2beta4 (same results): F:\bugReview>java TestLength TestLength.main(), Entering TestLength.getFileObject(), Created file object TestLength.main(), Created single folder with name length of 247 TestLength.getFileObject(), Created file object TestLength.main(), Create single folder with name length of 248 FAILED TestLength.getFileObject(), Created file object TestLength.main(), Created double folder with name length of 247 TestLength.getFileObject(), Created file object TestLength.main(), Create double folder with name length of 248 FAILED TestLength.getFileObject(), Created file object TestLength.main(), Created single folder with name length of 212 TestLength.main(), Wrote file with name length of 46 into folder with name length of 212 with separator makes 258 TestLength.getFileObject(), Created file object TestLength.main(), Created single folder with name length of 213 TestLength.writeFile(), Exception[java.io.FileNotFoundException: c:\this_is_1_folder_with_a_213_character_name_length____this_string_happens_to_be_50_characters_long______this_string_happens_to_be_50_characters_long______this_string_happens_to_be_50_characters_long___123456789_\this_file_has_a_46_character_name_length.bytes] java.io.FileNotFoundException: c:\this_is_1_folder_with_a_213_character_name_length____this_string_happens_to_be_50_characters_long______this_string_happens_to_be_50_characters_long______this_string_happens_to_be_50_characters_long___123456789_\this_file_has_a_46_character_name_length.bytes at java.lang.Throwable.<init>(Compiled Code) at java.io.FileOutputStream.<init>(Compiled Code) at java.io.FileOutputStream.<init>(Compiled Code) at TestLength.writeFile(Compiled Code) at TestLength.main(TestLength.java:284) TestLength.main(), Write file with name length of 46 into folder with name length of 213 with separator makes 259 FAILED TestLength.main(), Leaving (Review ID: 33432) ======================================================================