FileUtil { public static void copy(@NotNull File from, @NotNull File to) throws IOException { Validate.notNull(from); Validate.notNull(to); copy(from.toPath(), to.toPath()); }  static byte[] toByteArray(final File file); static String toString(final File file); static List<String> toLines(final File file); static void write(final CharSequence data, final File file); static void append(final CharSequence data, final File file); static InputStream asInputStream(String fileName); static InputStream asInputStream(File file); static InputStream asInputStream(Path path); static OutputStream asOututStream(String fileName); static OutputStream asOututStream(File file); static OutputStream asOututStream(Path path); static BufferedReader asBufferedReader(String fileName); static BufferedReader asBufferedReader(Path path); static BufferedWriter asBufferedWriter(String fileName); static BufferedWriter asBufferedWriter(Path path); static void copy(@NotNull File from, @NotNull File to); static void copy(@NotNull Path from, @NotNull Path to); static void copyFile(@NotNull File from, @NotNull File to); static void copyFile(@NotNull Path from, @NotNull Path to); static void copyDir(@NotNull File from, @NotNull File to); static void copyDir(@NotNull Path from, @NotNull Path to); static void moveFile(@NotNull File from, @NotNull File to); static void moveFile(@NotNull Path from, @NotNull Path to); static void moveDir(@NotNull File from, @NotNull File to); static void touch(String filePath); static void touch(File file); static void deleteFile(@Nullable File file); static void deleteFile(@Nullable Path path); static void deleteDir(Path dir); static void deleteDir(File dir); static boolean isDirExists(String dirPath); static boolean isDirExists(Path dirPath); static boolean isDirExists(File dir); static void makesureDirExists(String dirPath); static void makesureDirExists(File file); static void makesureDirExists(Path dirPath); static void makesureParentDirExists(File file); static boolean isFileExists(String fileName); static boolean isFileExists(File file); static boolean isFileExists(Path path); static Path createTempDir(); static Path createTempFile(); static Path createTempFile(String prefix, String suffix); static String getFileName(@NotNull String fullName); static String getFileExtension(File file); static String getFileExtension(String fullName);  }
@Test public void testCopy() throws Exception { Path dir = FileUtil.createTempDir(); assertThat(dir).exists(); String srcFileName = "src"; File srcFile = dir.resolve(srcFileName).toFile(); FileUtil.touch(srcFile); assertThat(srcFile).exists(); FileUtil.write("test", srcFile); String destFileName = "dest"; File destFile = new File(dir.toFile(), "parent1/parent2/" + destFileName); FileUtil.makesureParentDirExists(destFile); FileUtil.copy(srcFile, destFile); assertThat(Files.readFirstLine(destFile, Charsets.UTF_8)).isEqualTo("test"); }