忍者ブログ
メモ、備忘録、その他雑記を記載します。 ただし、このHPに記載している情報を利用した結果 損失・損害等が発生したとしても筆者は責任を持ちません。
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

javaでプロパティファイルを読み込む処理です。
 

import java.util.Properties;
import java.util.Enumeration;
import java.io.*;


public class Main {

 public static void main( String[] strArg ) {

  try {
   Properties prop = new Properties();
   Reader r = new InputStreamReader(Main.class.getResourceAsStream("setting.properties"));
   prop.load( r );

   // キー一覧表示
   Enumeration e = prop.propertyNames();
   while( e.hasMoreElements()) {
    System.out.println( "キー:" + e.nextElement());
   }

   // キーに対応した値表示
   System.out.println( "キー:" + prop.getProperty("123"));
   System.out.println( "キー:" + prop.getProperty("456"));
   System.out.println( "キー:" + prop.getProperty("789"));

  } catch (Exception e) {
   System.out.println("Exception:" + e);
  }
 
  return;
 }

 void Main() {
 }
}

setting.propatiesの内容
123 = 11111
456 = 22222
789 = 33333

 

拍手[0回]

PR
コメントを書く
お名前
タイトル
メールアドレス
URL
コメント   Vodafone絵文字 i-mode絵文字 Ezweb絵文字
パスワード
 HOME | 18  17  16  13  12  11  10  9  8  7  6 
Admin / Write
カレンダー
05 2025/06 07
S M T W T F S
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
フリーエリア
最新コメント
最新トラックバック
プロフィール
HN:
Ace
性別:
非公開
バーコード
ブログ内検索
P R
忍者アナライズ
忍者ブログ [PR]