LoginSignup
4
1

More than 5 years have passed since last update.

POJOでのプロパティ読み込み

Posted at

POJOでプロパティを読みこむ実装のサンプルです。

package sample;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Locale;
import java.util.Properties;
import java.util.ResourceBundle;

public class propertyApp {

    public static void main(String[] args) throws FileNotFoundException, IOException {
        ResourceBundle rb = ResourceBundle.getBundle("sample", Locale.getDefault());
        System.out.println(rb.getString("project_id"))  ;
        System.out.println(rb.getString("project_name"));

        Properties p = new Properties();
        p.load(new FileInputStream("resources/sample.properties"));
        System.out.println(p.getProperty("project_id"));
        System.out.println(p.getProperty("project_name"));
    }

}
4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1