1326 * along with all necessary parent directories; <code>false</code> 1327 * otherwise 1328 * 1329 * @throws SecurityException 1330 * If a security manager exists and its <code>{@link 1331 * java.lang.SecurityManager#checkRead(java.lang.String)}</code> 1332 * method does not permit verification of the existence of the 1333 * named directory and all necessary parent directories; or if 1334 * the <code>{@link 1335 * java.lang.SecurityManager#checkWrite(java.lang.String)}</code> 1336 * method does not permit the named directory and all necessary 1337 * parent directories to be created 1338 */ 1339 public boolean mkdirs() { 1340 if (exists()) { 1341 return false; 1342 } 1343 if (mkdir()) { 1344 return true; 1345 } 1346 File canonFile = null; 1347 try { 1348 canonFile = getCanonicalFile(); 1349 } catch (IOException e) { 1350 return false; 1351 } 1352 1353 File parent = canonFile.getParentFile(); 1354 return (parent != null && (parent.mkdirs() || parent.exists()) && 1355 canonFile.mkdir()); 1356 } 1357 1358 /** 1359 * Renames the file denoted by this abstract pathname. 1360 * 1361 * <p> Many aspects of the behavior of this method are inherently 1362 * platform-dependent: The rename operation might not be able to move a 1363 * file from one filesystem to another, it might not be atomic, and it 1364 * might not succeed if a file with the destination abstract pathname 1365 * already exists. The return value should always be checked to make sure 1366 * that the rename operation was successful. 1367 * 1368 * <p> Note that the {@link java.nio.file.Files} class defines the {@link 1369 * java.nio.file.Files#move move} method to move or rename a file in a 1370 * platform independent manner. 1371 * 1372 * @param dest The new abstract pathname for the named file 1373 * 1374 * @return <code>true</code> if and only if the renaming succeeded; 1375 * <code>false</code> otherwise | 1326 * along with all necessary parent directories; <code>false</code> 1327 * otherwise 1328 * 1329 * @throws SecurityException 1330 * If a security manager exists and its <code>{@link 1331 * java.lang.SecurityManager#checkRead(java.lang.String)}</code> 1332 * method does not permit verification of the existence of the 1333 * named directory and all necessary parent directories; or if 1334 * the <code>{@link 1335 * java.lang.SecurityManager#checkWrite(java.lang.String)}</code> 1336 * method does not permit the named directory and all necessary 1337 * parent directories to be created 1338 */ 1339 public boolean mkdirs() { 1340 if (exists()) { 1341 return false; 1342 } 1343 if (mkdir()) { 1344 return true; 1345 } 1346 File parent = getParentFile(); 1347 if (parent == null) { 1348 return false; 1349 } 1350 parent.mkdirs(); 1351 return mkdir(); 1352 } 1353 1354 /** 1355 * Renames the file denoted by this abstract pathname. 1356 * 1357 * <p> Many aspects of the behavior of this method are inherently 1358 * platform-dependent: The rename operation might not be able to move a 1359 * file from one filesystem to another, it might not be atomic, and it 1360 * might not succeed if a file with the destination abstract pathname 1361 * already exists. The return value should always be checked to make sure 1362 * that the rename operation was successful. 1363 * 1364 * <p> Note that the {@link java.nio.file.Files} class defines the {@link 1365 * java.nio.file.Files#move move} method to move or rename a file in a 1366 * platform independent manner. 1367 * 1368 * @param dest The new abstract pathname for the named file 1369 * 1370 * @return <code>true</code> if and only if the renaming succeeded; 1371 * <code>false</code> otherwise |