above question Solution is below working
:-
public class LoadFileFromInsideJarResourceFolder {
<code>public void getFileFromInsideJarResourceFolder() throws IOException {
List<InputStream> inputStreamArray = new ArrayList<>();
ClassLoader cl = this.getClass().getClassLoader();
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(cl);
/*use your folder name or use without folder name if u dont have folder and your file is in resource folder*/
Resource[] resources = resolver.getResources("classpath:folder name/**");
for(Resource resource :resources){
if (resource.isReadable()) {
inputStreamArray.add(resource.getInputStream());
}
}
for(InputStream inputStream :inputStreamArray){
File file = File.createTempFile("temp-file-any-name", ".xml(use any file format)");
try {
FileUtils.copyInputStreamToFile(inputStream, file);
} finally {
IOUtils.closeQuietly(inputStream);
}
// use this fileContent as per your requirement
}
}
</code>
<code>public void getFileFromInsideJarResourceFolder() throws IOException {
List<InputStream> inputStreamArray = new ArrayList<>();
ClassLoader cl = this.getClass().getClassLoader();
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(cl);
/*use your folder name or use without folder name if u dont have folder and your file is in resource folder*/
Resource[] resources = resolver.getResources("classpath:folder name/**");
for(Resource resource :resources){
if (resource.isReadable()) {
inputStreamArray.add(resource.getInputStream());
}
}
for(InputStream inputStream :inputStreamArray){
File file = File.createTempFile("temp-file-any-name", ".xml(use any file format)");
try {
FileUtils.copyInputStreamToFile(inputStream, file);
} finally {
IOUtils.closeQuietly(inputStream);
}
// use this fileContent as per your requirement
}
}
</code>
public void getFileFromInsideJarResourceFolder() throws IOException {
List<InputStream> inputStreamArray = new ArrayList<>();
ClassLoader cl = this.getClass().getClassLoader();
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(cl);
/*use your folder name or use without folder name if u dont have folder and your file is in resource folder*/
Resource[] resources = resolver.getResources("classpath:folder name/**");
for(Resource resource :resources){
if (resource.isReadable()) {
inputStreamArray.add(resource.getInputStream());
}
}
for(InputStream inputStream :inputStreamArray){
File file = File.createTempFile("temp-file-any-name", ".xml(use any file format)");
try {
FileUtils.copyInputStreamToFile(inputStream, file);
} finally {
IOUtils.closeQuietly(inputStream);
}
// use this fileContent as per your requirement
}
}
}
Nothing….Solution is working!!!
New contributor
user24689051 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.