Skip to content
This repository was archived by the owner on Dec 29, 2025. It is now read-only.

Commit aa38822

Browse files
authored
Update FileUtils.java
1 parent de47d24 commit aa38822

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/main/java/id.my.alvinq.prokitid.libs/FileUtils.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,34 @@
55
import java.nio.file.attribute.BasicFileAttributes;
66

77
public class FileUtils {
8+
89
public static void copyFile(String from, String to) {
910
try {
1011
Files.copy(Paths.get(from), Paths.get(to), StandardCopyOption.REPLACE_EXISTING);
11-
} catch (IOException error) {
12-
}
12+
} catch (IOException error) {}
13+
}
14+
15+
public static void copyFolder(String source, String target) {
16+
try {
17+
final Path from = Paths.get(source);
18+
final Path to = Paths.get(target);
19+
20+
Files.walkFileTree(from, new SimpleFileVisitor<Path>() {
21+
@Override
22+
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
23+
Path targetDir = to.resolve(from.relativize(dir));
24+
if (!Files.exists(targetDir)) {
25+
Files.createDirectories(targetDir);
26+
}
27+
return FileVisitResult.CONTINUE;
28+
}
29+
30+
@Override
31+
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
32+
Files.copy(file, to.resolve(from.relativize(file)), StandardCopyOption.REPLACE_EXISTING);
33+
return FileVisitResult.CONTINUE;
34+
}
35+
});
36+
} catch (IOException error) {}
1337
}
1438
}

0 commit comments

Comments
 (0)