1 2 import java.io.*;
3 import java.util.*;
4 5 6 /* Demonstration of how Resource Bundle works By MD Harrington 19 June 2005 */
7 8 /* A Simple console demonstration to show how we can use a resource Bundle to list
9 Known Key pairs */
10 11 /* 1: What would we use this for lanaguage converters
12 2: Currency Converters
13 3: Populating Option Select objects in an Html Form
14 4: Military applications for Coding of words Every time you whish to reencode a
15 word you might use
16 a Rescource Bundle to do this
17 5: Scientific uses
18 19 Thats Five i can think of straight away
20 21 */
22 23 24 25 26 publicclass DemoResourceBundle
27 {
28 publicstaticvoid main(String[] args)
29 {
30 // this where we create the resource bundle object
31 32 ResourceBundle res = ResourceBundle.getBundle("CurrencyConverstions");
33 34 // if you know the key you can return the associated string ;
35 System.out.println(" If you know the key then get associated string with key ");
36 System.out.println(" Here is the String association with known Key = AFA " +
37 res.getString("AFA"));
38 39 // Now of course your starting to think further than this and if we don't know
40 the key lets list it
41 42 // what can we do with this you might ask
43 44 // How about populating a Option select Box on an html page sounds quite good
45 doesn't it !!
46 47 // Now lets see what we have in the bundle
48 49 50 51 Enumeration enum = res.getKeys(); // get an enumeration object of the bundle keys
52 53 while (enum.hasMoreElements())
54 {
55 String myKey = (String)enum.nextElement(); // cast the Object to a String type
56 Object
57 // Now lets get each association with the key and list the key + the association
58 System.out.println("Key = " + myKey + " Country = " + res.getString(myKey) );
59 60 }
61 62 63 64 65 }// end static main
66 67 }