- Create an object of Properties class.
- Load properties file using FileInputStream into properties object.
- Get value from properties object using getProperty() method passing key as an input.
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
public class PropertiesReadTest {
public static void main(String[] args) {
Properties properties = new Properties();
try {
properties.load(new FileInputStream("C:\\temp\\test.properties"));
String value = properties.getProperty("key");
System.out.println("Value = " + value);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Output is shown here in following image