public static void copyFile(String source, String target) throws IOException {
        File sf = new File(source);
        if (!sf.exists()) {
            throw new IllegalArgumentException("source file does not exist.");
        }
        File tf = new File(target);
        if (!tf.getParentFile().mkdirs()) {
            throw new RuntimeException("failed to create parent directory.");
        }
        if (!tf.exists() && !tf.createNewFile()) {
            throw new RuntimeException("failed to create target file.");
        }
        try (
                FileChannel sc = new FileInputStream(sf).getChannel();
                FileChannel tc = new FileOutputStream(tf).getChannel()) {
            sc.transferTo(0, sc.size(), tc);
        }
    }
@Test
    public void testCopyFile() throws Exception {
        String sourcePath = sourceFile.getAbsolutePath();
        String targetPath = sourceFile.getParent() + File.separator + "copy" + File.separator + "target.txt";
        IoUtil.copyFile(sourcePath, targetPath);
        File targetFile = new File(targetPath);
        Assert.assertTrue(targetFile.exists());
        Assert.assertEquals(sourceFile.length(), targetFile.length());
        byte[] sourceBytes = Files.readAllBytes(sourceFile.toPath());
        byte[] targetBytes = Files.readAllBytes(targetFile.toPath());
        Assert.assertArrayEquals(sourceBytes, targetBytes);
    }