Java Tutorial
IntroductionEnvironment SetupIDEBuild ManagementLanguage SpecificationBasic ProgramVariables Data TypesPackagesModifiersConditionalsLoopsObject OrientedClassesSuperInterfacesEnumStatic importInheritanceAbstractionEncapsulationPolymorphismBoxing & UnboxingConversion Formatting numbers Arrays Command line arguments in java Variable Number of arguments in Java Exception handling in Java String handling in Java StringBuffer and StringBuilder in Java Mathematical Operations in Java Date and Time in Java Regular expressions in Java Input output programming in Java File Handling Nested Classes Collections Generics Serialization Socket programming Multi-Threading Annotations Lambda Expressions Reflections in Java Singleton class in Java Runtime Class in JavaHow to load resource in JavaHow to load properties file in JavaAdvanced
Log4j – Logging framework in JavaInterview Questions in JavaLoad resources in Java
We can load resources using getResource or getResourceAsStream method of ClassLoader.
import java.io.InputStream;
import java.util.Properties;
public class PropertyTest {
public static void main(String[] args) {
String resourceName = "Environment.properties";
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Properties props = new Properties();
try{
InputStream resourceStream =
loader.getResourceAsStream(resourceName);
props.load(resourceStream);
System.out.println("webserver.url -> " + props.getProperty("webserver.url"));
}catch (Exception ex){
System.out.println("Exception ");
}
}
}
Here is the output of above example.
webserver.url -> https://www.softpost.org
Web development and Automation testing
solutions delivered!!