From 0766ec38057e9e1e2d35ae5b6d483c062eba75cb Mon Sep 17 00:00:00 2001 From: xtaodada Date: Fri, 20 May 2022 23:15:24 +0800 Subject: [PATCH] Fix dataloader not getting path correctly --- .../java/emu/grasscutter/utils/FileUtils.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main/java/emu/grasscutter/utils/FileUtils.java b/src/main/java/emu/grasscutter/utils/FileUtils.java index 61ed6b443..ae0be71ca 100644 --- a/src/main/java/emu/grasscutter/utils/FileUtils.java +++ b/src/main/java/emu/grasscutter/utils/FileUtils.java @@ -9,7 +9,6 @@ import java.net.URI; import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; import java.nio.file.*; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -77,19 +76,18 @@ public final class FileUtils { } // From https://mkyong.com/java/java-read-a-file-from-resources-folder/ - public static List getPathsFromResource(String folder) throws URISyntaxException, IOException { + public static List getPathsFromResource(String folder) throws URISyntaxException { List result = null; - - // Get path of the current running JAR - String jarPath = Grasscutter.class.getProtectionDomain() + + // Get pathUri of the current running JAR + URI pathUri = Grasscutter.class.getProtectionDomain() .getCodeSource() .getLocation() - .toURI() - .getPath(); + .toURI(); try { // file walks JAR - URI uri = URI.create("jar:file:" + jarPath); + URI uri = URI.create("jar:file:" + pathUri.getRawPath()); try (FileSystem fs = FileSystems.newFileSystem(uri, Collections.emptyMap())) { result = Files.walk(fs.getPath(folder)) .filter(Files::isRegularFile) @@ -105,7 +103,7 @@ public final class FileUtils { result = Arrays.stream(f.listFiles()).map(File::toPath).toList(); } - + return result; }