GetResource with a link to the parent directory

I have a java application where I am trying to download a text file that will be included in a jar.

When I do getClass().getResource("/a/b/c/"), it can create a URL for this path, and I can print it, and everything looks fine.

However, if I try getClass().getResource(/a/b/../"), I get the URL nullback.

It doesn't seem to like ..on the go. Does anyone see what I'm doing wrong? I can post more code if this is helpful.

+5
source share
2 answers

normalize()methods (four of them) in the class FilenameUtilscan help you. It is located in the Apache Commons IO library .

final String name =  "/a/b/../";
final String normalizedName = FilenameUtils.normalize(name, true); // "/a/"
getClass().getResource(normalizedName);
+5

, getResource(), , File ( ilk). , ?

+2

All Articles