//: # ()
Here are the steps to read a properties file in Java using bullet points:
Import the java.util.Properties
class.
Create a new Properties
object.
Create a new FileInputStream
object and pass the path of the properties file as an argument.
Load the properties file into the Properties
object using the load()
method of the Properties
class.
Access the properties of the file using the getProperty()
method of the Properties
class.
Here’s an example of how to read a properties file using this class:
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
public class ReadPropertiesFile {
public static void main(String[] args) {
Properties prop = new Properties();
try {
FileInputStream fis = new FileInputStream("config.properties");
prop.load(fis);
System.out.println(prop.getProperty("database"));
System.out.println(prop.getProperty("dbuser"));
System.out.println(prop.getProperty("dbpassword"));
} catch (IOException ex) {
ex.printStackTrace();
}
}
}