I am running local code in traditional tomcat server where as while deploying to Kubernetes my code of read resource file is not working.
I placed nas.txt
in resource folder.
and
File file = ResourceUtils.getFile("classpath:nas.txt");
//Read File Content
String content = new String(Files.readAllBytes(file.toPath()));
return content;
This is giving "Internal exception has occurred"
error
ResourceUtils.getFile
doesn't work with packaged jars. Though it works with IDEs. You can try below alternate
protected InputStreamReader readStream(String filePath) throws FileNotFoundException {
InputStreamReader streamReader;
if (filePath.startsWith("classpath:")) {
streamReader = new InputStreamReader(getClass().getResourceAsStream(File.separator + filePath.split("classpath:/*")[1]));
} else {
streamReader = new FileReader(ResourceUtils.getFile(filePath));
}
return streamReader;
}
Is the file present in tomcat - - >webapps -->app°war--> resources inside the container