リソースバンドルをAppletから利用する方法です。便利なのでよく使います。
普通に昔のWindowsのINIファイルのように使ってます。
自分でファイルを開いたり、行を読んだりしなくてよいので便利です。
MyApplet.propertiesはアップレットのJARファイルと同じ場所においておきます。
InputStream propertyStream = null; try { URL propertyURL = new URL(getCodeBase(), "MyApplet.properties"); propertyStream = propertyURL.openConnection().getInputStream(); } catch (Exception e) { e.printStackTrace(); return; }
// InputStreamをPropertiesの入力として指定 Properties prop = new Properties(); try { prop.load(propertyStream); //念のため出力 Enumeration e = prop.propertyNames(); while (e.hasMoreElements()) { System.out.println("name="+e.nextElement().toString()); } } catch (IOException e) { e.printStackTrace(); return; } //値を取得する。 String url = prop.getProperty("url");
|