Moves a file from one path to another. This method can rename a file and/or move it to a different directory. In either case {@code to} must be the target path for the file itself; not just the new name for the file or the path to the new parent directory. <p><b>{@link java.nio.file.Path} equivalen
(File from, File to)
| 489 | * @throws IllegalArgumentException if {@code from.equals(to)} |
| 490 | */ |
| 491 | public static void move(File from, File to) throws IOException { |
| 492 | checkNotNull(from); |
| 493 | checkNotNull(to); |
| 494 | checkArgument(!from.equals(to), "Source %s and destination %s must be different", from, to); |
| 495 | |
| 496 | if (!from.renameTo(to)) { |
| 497 | copy(from, to); |
| 498 | if (!from.delete()) { |
| 499 | if (!to.delete()) { |
| 500 | throw new IOException("Unable to delete " + to); |
| 501 | } |
| 502 | throw new IOException("Unable to delete " + from); |
| 503 | } |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | /** |
| 508 | * Reads the first line from a file. The line does not include line-termination characters, but |