Java method instance analysis to read the properties file

  • 2020-04-01 03:56:43
  • OfStack

This article illustrates how Java can read the properties file. Share with you for your reference. Specific analysis is as follows:

1. Not reading in the project:


Properties properties = new Properties();
BufferedReader read = new BufferedReader(new InputStreamReader(new FileInputStream(" Path to file "),"utf-8"));
properties.load(read);
properties .getProperty(" Of that document key")

2. Read in the project:


InputStream inputStream = The class name of your utility class .class.getResourceAsStream("/ The file name .properties");
Properties p = new Properties();
try {
p.load(inputStream);
inputStream.close();
} catch (IOException e1) {
e1.printStackTrace();
}

All values are obtained through p.geetproperty

I hope this article has been helpful to your Java programming.


Related articles: