diff --git a/pom.xml b/pom.xml index 24235b0..cf7c56d 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ io.github.umutayb Utilities - 1.7.5 + 1.7.6 jar Java-Utilities diff --git a/src/main/java/utils/FileUtilities.java b/src/main/java/utils/FileUtilities.java index 3430447..c502bf9 100644 --- a/src/main/java/utils/FileUtilities.java +++ b/src/main/java/utils/FileUtilities.java @@ -23,10 +23,7 @@ import java.io.*; import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; +import java.nio.file.*; import java.util.*; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; @@ -38,6 +35,25 @@ public class FileUtilities { static Printer log = new Printer(FileUtilities.class); + /** + * Checks if a given string is a valid file path. + * + * @param path The string representing the file path to validate. + * @return true if the string is a valid file path, false otherwise. + */ + public static boolean isValidFilePath(String path) { + if (path == null || path.isEmpty()) return false; + + try { + Path filePath = Paths.get(path); + filePath.toRealPath(); + return true; + } + catch (InvalidPathException | SecurityException | IOException e) { + return false; + } + } + /** * Retrieves the Base64-encoded string representation of an image file. *