Skip to content

Commit 7b27873

Browse files
committed
Update FileUtils.java
1 parent 5e488ba commit 7b27873

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

src/main/java/io/github/intisy/utils/utils/FileUtils.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public static void delete(File file) {
2727
if (!file.delete())
2828
throw new RuntimeException("Failed to delete file " + file);
2929
}
30+
public static void mkdirs(String file) {
31+
mkdirs(new File(file));
32+
}
3033
public static void mkdirs(File file) {
3134
if (!file.exists())
3235
if (!file.mkdirs())
@@ -60,24 +63,19 @@ public static void displayFileContent(File file) {
6063
}
6164
public static void copyFolder(File source, File destination) {
6265
try {
63-
// Check if source is a directory
6466
if (source.isDirectory()) {
65-
// If destination directory does not exist, create it
6667
if (!destination.exists()) {
6768
destination.mkdir();
6869
}
6970

70-
// List all files and directories in the source directory
7171
String[] files = source.list();
7272

7373
if (files != null) {
7474
for (String file : files) {
75-
// Recursively copy files and directories
7675
copyFolder(new File(source, file), new File(destination, file));
7776
}
7877
}
7978
} else {
80-
// If source is a file, copy it to the destination directory
8179
try {
8280
Files.copy(source.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING);
8381
} catch (AccessDeniedException ignored) {
@@ -113,23 +111,19 @@ public static File resourceToFile(Class<?> resourceClass, String path) {
113111
}
114112

115113
public static void deleteFolder(File folder) {
116-
// Check if the given File object represents a directory
117114
if (folder.isDirectory()) {
118-
// List all files and subdirectories in the directory
119115
File[] files = folder.listFiles();
120116

121117
if (files != null) {
122-
// Recursively delete each file and subdirectory
123118
for (File file : files) {
124119
deleteFolder(file);
125120
}
126121
}
127122
}
128123

129-
// Delete the empty directory or file
130124
folder.delete();
131125
}
132-
public static File file(String file) {
126+
public static File cleanFile(String file) {
133127
File f = new File(file);
134128
if (f.exists())
135129
if (!f.delete())

0 commit comments

Comments
 (0)