aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/makamys/lodmod/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/makamys/lodmod/util')
-rw-r--r--src/main/java/makamys/lodmod/util/Util.java30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/main/java/makamys/lodmod/util/Util.java b/src/main/java/makamys/lodmod/util/Util.java
new file mode 100644
index 0000000..92cc5cd
--- /dev/null
+++ b/src/main/java/makamys/lodmod/util/Util.java
@@ -0,0 +1,30 @@
+package makamys.lodmod.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.nio.file.FileSystems;
+import java.nio.file.Path;
+
+public class Util {
+ public static Path getResourcePath(String relPath) {
+ try {
+ URL resourceURL = Util.class.getClassLoader().getResource(relPath);
+
+ switch(resourceURL.getProtocol()) {
+ case "jar":
+ String urlString = resourceURL.getPath();
+ int lastExclamation = urlString.lastIndexOf('!');
+ String newURLString = urlString.substring(0, lastExclamation);
+ return FileSystems.newFileSystem(new File(URI.create(newURLString)).toPath(), null).getPath(relPath);
+ case "file":
+ return new File(URI.create(resourceURL.toString())).toPath();
+ default:
+ return null;
+ }
+ } catch(IOException e) {
+ return null;
+ }
+ }
+}