I am encountering a FileNotFoundException when loading a JSON file that is in the path of a Java Java container using docker containers, this is a Spring-Boot application. This JSON file is available in the resource folder. I can see the JSON file in the docker in the directory. / target / classes /.
Resource resource = resourceLoader.getResource("classpath:folderNm/file.json"); HashMap<String, String> headerMapping = (HashMap<String, String>) parser.parse(new FileReader(resource.getFile().getAbsolutePath()));
But I get this exception:
java.io.FileNotFoundException: class path resource [folderNm/file.json] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/app.jar!/folderNm/file.json
I tried
-> resource.getFile().getPath(); -> resource.getFile().getCanonicalPath(); -> " ./target/classes/folderName/fileName " (location of the FilePath hard drive) -> " /app.jar!/folderNm/file.json " (location of the FilePath hard drive)
InputStream inputStream = getClass().getResourceAsStream("xyz.json"); BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); StringBuilder responseStrBuilder = new StringBuilder(); String inputStr; while ((inputStr = br.readLine()) != null) responseStrBuilder.append(inputStr);
none of the above methods work. Please suggest a way to solve this problem.
source share