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 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. @param from the source file @param to the
(File from, File to)
| 473 | * @throws IllegalArgumentException if {@code from.equals(to)} |
| 474 | */ |
| 475 | public static void move(File from, File to) throws IOException { |
| 476 | checkNotNull(from); |
| 477 | checkNotNull(to); |
| 478 | checkArgument(!from.equals(to), "Source %s and destination %s must be different", from, to); |
| 479 | |
| 480 | if (!from.renameTo(to)) { |
| 481 | copy(from, to); |
| 482 | if (!from.delete()) { |
| 483 | if (!to.delete()) { |
| 484 | throw new IOException("Unable to delete " + to); |
| 485 | } |
| 486 | throw new IOException("Unable to delete " + from); |
| 487 | } |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | /** |
| 492 | * Reads the first line from a file. The line does not include line-termination characters, but |
nothing calls this directly
no test coverage detected