Many similar questions have been asked, but there's only so much pain I can take before I have to ask the question myself.
Anyway, I have files in jar file
/input, and I need to read the list of the names of the files in that folder (and later, read the files themselves.)
Attempt #1:
String path Main.class.getProtectionDomain().getCodeSource().getLocation().getPath();
// "/Applications/company/extensions/components/Box/Box/Box.jar"
String decoded = URLDecoder.decode(path, "UTF-8");
// "/Applications/company/extensions/components/Box/Box/Box.jar"
File[] files = (new File(decoded + "/input")).listFiles();
// files = null (bad)
Attempt #2:
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
URL url = classLoader.getResource("input");
// url.file: "file:/Applications/company/extensions/components/Box/Box/Box.jar!/input"
// url.path: (ditto)
// url.protocol: "jar"
// url.host: ""
// url.query: null
// url.port: -1
java.net.URI uri = new java.net.URI(url.getProtocol(), url.getAuthority(), url.getPort(), url.getPath(), url.getQuery(), url.getRef());
// URISyntaxException --> "Relative path in absolute URI" (bad)
Other miscellaneous attempts in-between which had the same result. I simply cannot read the folder in that jar...
Anybody know how to fix this?