「Java」properties ファイルからの値を取得するサンプルコード

1.kuroapp.properties
username = root
password = 123456
2.PropRead.java
import java.util.Properties;
import java.io.FileInputStream;
import java.io.InputStream;

public class PropRead {
public static void main (String[] args) {

Properties properties = new Properties();

String file = “/dara/kuroapp.properties";
try {
InputStream inputStream = new FileInputStream(file);
properties.load(inputStream);
inputStream.close();

System.out.println(properties.getProperty(“username"));
System.out.println(properties.getProperty(“password"));

} catch (Exception ex) {
System.out.println(ex.getMessage());

}

}
}

Java

Posted by arkgame