Gets the absolute path of the specified file. @param file the file @return the absolute path, with forward slashes
(File file)
| 432 | * @return the absolute path, with forward slashes |
| 433 | */ |
| 434 | public static String getAbsolutePath(File file) { |
| 435 | if (file == null) { |
| 436 | return null; |
| 437 | } |
| 438 | String path = forwardSlash(file.getAbsolutePath()); |
| 439 | int n = path.indexOf("/../"); //$NON-NLS-1$ |
| 440 | while (n >= 0) { |
| 441 | String pre = path.substring(0, n); |
| 442 | int m = pre.lastIndexOf("/"); //$NON-NLS-1$ |
| 443 | if (m < 0) |
| 444 | break; |
| 445 | String post = path.substring(n + 3); |
| 446 | path = pre.substring(0, m) + post; |
| 447 | n = path.indexOf("/../"); //$NON-NLS-1$ |
| 448 | } |
| 449 | n = path.indexOf("/./"); //$NON-NLS-1$ |
| 450 | while (n >= 0) { |
| 451 | path = path.substring(0, n) + path.substring(n + 2); |
| 452 | n = path.indexOf("/./"); //$NON-NLS-1$ |
| 453 | } |
| 454 | return path; |
| 455 | } |
| 456 | |
| 457 | /** |
| 458 | * Resolves the name of a file specified relative to a base path. |