How to get absolute path with proper character encoding in Java?
The URL.getFile
call you are using returns the file part of a URL encoded according to the URL encoding rules. You need to decode the string using URLDecoder
before giving it to File
:
String path = Swagger2MarkupConverterTest.class.getResource(
"/json/swagger.json").getFile();
path = URLDecoder.decode(path, "UTF-8");
File file = new File(path);