📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (176K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.Properties; /** * @author Ramesh Fadatare * */ public class PropertiesFileReader { private static Properties prop = null; private static final String propFileName = "config.properties"; private static void loadPropValues() throws IOException { prop = new Properties(); InputStream inputStream = PropertiesFileReader.class.getClassLoader().getResourceAsStream(propFileName); prop.load(inputStream); if (inputStream == null) { throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath"); } } public static String getValue(String key) throws IOException { if (prop == null) { loadPropValues(); } return prop.getProperty(key); } public static String getValue(String key, String defaultvalue) throws IOException { if (prop == null) { loadPropValues(); } return prop.getProperty(key, defaultvalue); } }
Comments
Post a Comment
Leave Comment