Properties File Reading Example
This program demonstrates reading properties from a .properties file.
Problem Statement
Write a Java program that reads key-value pairs from a properties file.
Source Code
| 1 | import java.io.*; |
| 2 | import java.util.*; |
| 3 | public class ReadPropertiesExample { |
| 4 | public static void main(String[] args) { |
| 5 | System.out.println("Eduinq Read Properties Example"); |
| 6 | Properties p=new Properties(); |
| 7 | try(FileReader fr=new FileReader("config.properties")) { |
| 8 | p.load(fr); |
| 9 | System.out.println("Eduinq Username: "+p.getProperty("username")); |
| 10 | System.out.println("Eduinq Password: "+p.getProperty("password")); |
| 11 | } catch(IOException e) { |
| 12 | System.out.println("Eduinq Exception: "+e.getMessage()); |
| 13 | } |
| 14 | } |
| 15 | } |
Program Output
Eduinq Read Properties Example Eduinq Username: admin Eduinq Password: 12345
Explanation
Properties files store configuration in key-value format. - Properties.load() reads data easily. - Exception handling ensures safe operations. - In enterprise systems, properties files are used for environment settings. Conclusion: Shows reading properties files.