Warning: include_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /home/users/2/moriya-h5/web/confrage/java/properties/properties/properties.html on line 2

Warning: include_once(http://www.confrage.com/bin/header.php): failed to open stream: no suitable wrapper could be found in /home/users/2/moriya-h5/web/confrage/java/properties/properties/properties.html on line 2

Warning: include_once(): Failed opening 'http://www.confrage.com/bin/header.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/properties/properties/properties.html on line 2
Propertiesクラス | Java | 株式会社CONFRAGE
Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/menu.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/properties/properties/properties.html on line 17

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/menu.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/properties/properties/properties.html on line 17
ファイルからロードする
Propertiesクラスはキーと値を持つクラスです。
Propertiesクラスで便利なのは一定の書式のファイルからキーと値を一度にセットすることが出来ることです。
ファイルをロードするにはload()メソッドを使用します。

ファイルの書式
キーとセットの組み合わせをプロパティと呼ぶ場合、プロパティは1行単位で記述します。
ファイルの各行の終端は(¥n、¥r、¥r¥n)で識別されます。
また、行の先頭に、#もしくは!を記述した場合、この行はコメント扱いとなりプロパティはセットされません。

プロパティは、キー=値もしくはキー:値と記述します。
イコールとの間に半角スペースがあっても問題ありません。

プロパティファイル
以下はプロパティファイルの例です。

user=conf
pass=1234
サンプル
以下はプロパティファイルをロードするサンプルです。

import java.io.FileInputStream;
import java.util.Properties;

public class Test{
    public static void main(String[] args){
        Properties prop = new Properties();
        try{
            prop.load(new FileInputStream("c:¥¥test.properties"));
        }catch(Exception e){
            e.printStackTrace();
        }
        System.out.println(prop.getProperty("DATABASE"));
    }
}
プロパティファイルc:¥test.propertiesは以下の通りとします。

DATABASE=oracle
出力結果は以下の通りとなります。

oracle

Back to top

Information

Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/side_bar.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/properties/properties/properties.html on line 123

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/side_bar.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/properties/properties/properties.html on line 123

Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/seo.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/properties/properties/properties.html on line 132

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/seo.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/properties/properties/properties.html on line 132