My linux world » Java – Classloader

Java - Classloader


Get Inputstream from file in the classpath

// retrieve classLoader from this current class:
ClassLoader classLoader = this.getClass().class.getClassLoader();
 
// now get "myfile.txt" inputstream:
if(classLoader!=null) {
  InputStream inputstream = classLoader.getResourceAsStream("myfile.txt");
}
else {
  logger.error("classLoader is null !");
}

Copyright © 2023 My linux world - by Marc RABAHI
Design by Marc RABAHI and encelades.

Fork me on GitHub