{"id":412,"date":"2003-06-01T23:37:13","date_gmt":"2003-06-02T03:37:13","guid":{"rendered":"http:\/\/wordpress.cephas.net\/?p=412"},"modified":"2003-06-01T23:37:13","modified_gmt":"2003-06-02T03:37:13","slug":"resourcebundles","status":"publish","type":"post","link":"https:\/\/cephas.net\/blog\/2003\/06\/01\/resourcebundles\/","title":{"rendered":"ResourceBundles"},"content":{"rendered":"<p>Update: A <a href=\"http:\/\/java.sun.com\/j2se\/1.4.1\/docs\/api\/java\/util\/ResourceBundle.html\">ResourceBundle<\/a> object is the way to go.  In comparison to the <a href=\"http:\/\/java.sun.com\/j2se\/1.4.1\/docs\/api\/java\/util\/Properties.html\">Properties<\/a> class, the ResourceBundle class is a breeze.  To load, read and retrieve the key &#8216;searchlib.dblibrary&#8217; from a text file called &#8216;database.properties&#8217; using the Properties class, you&#8217;d end up with something like this:<\/p>\n<p>String databaseDriver;<br \/>\ntry {<br \/>\n&nbsp;&nbsp;FileInputStream propFile = new FileInputStream(&#8220;c:\\\\myapp\\\\sandbox\\\\database.properties&#8221;);<br \/>\n&nbsp;&nbsp;Properties p = new Properties();<br \/>\n&nbsp;&nbsp;p.load(propFile);<br \/>\n&nbsp;&nbsp;databaseDriver = p.getProperty(&#8220;searchlib.dblibrary&#8221;);<br \/>\n} catch (java.io.FileNotFoundException fe) {}<br \/>\n} catch (java.io.IOException ie) {}<\/p>\n<p>where you have to hardcode the path to the properties file and if the path changes, you have to recompile.  <\/p>\n<p>To do the same thing with the ResourceBundle class, you&#8217;d end up with something like this:<\/p>\n<p>String databaseDriver;<br \/>\nResourceBundle res = ResourceBundle.getBundle(&#8220;database&#8221;);<br \/>\ndatabaseDriver = res.getString(&#8220;searchlib.dblibrary&#8221;);<\/p>\n<p>The file this time is located by JVM, located somewhere in the classpath.  No try\/catch is necessary.  Alot easier isn&#8217;t it?  <\/p>\n<p>If you&#8217;re interested in reading more about the ResourceBundle class, check out this article on developer.java.sun.com:<\/p>\n<p><a href=\"http:\/\/developer.java.sun.com\/developer\/technicalArticles\/Intl\/ResourceBundles\/\">Java Internationalization: Localization with ResourceBundles<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Update: A ResourceBundle object is the way to go. In comparison to the Properties class, the ResourceBundle class is a breeze. To load, read and retrieve the key &#8216;searchlib.dblibrary&#8217; from a text file called &#8216;database.properties&#8217; using the Properties class, you&#8217;d end up with something like this: String databaseDriver; try { &nbsp;&nbsp;FileInputStream propFile = new FileInputStream(&#8220;c:\\\\myapp\\\\sandbox\\\\database.properties&#8221;); &hellip; <a href=\"https:\/\/cephas.net\/blog\/2003\/06\/01\/resourcebundles\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">ResourceBundles<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts\/412"}],"collection":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/comments?post=412"}],"version-history":[{"count":0,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts\/412\/revisions"}],"wp:attachment":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/media?parent=412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/categories?post=412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/tags?post=412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}