This is because of a classpath issue between resources and files. We can not use classloaders to access files. For that we need to use File, filereader, file input stream. After changing like this everything works fine;
InputStream in = new FileInputStream(filePath);