It can be easely done by creating a 2D array in the code. But hard coding that kind of information is not good programming practice therefore I decided to create a property file which had that information.
If the user want to change what is in the drop down meneu he can easily do it by changing the property file that is the advantage of having a property file.
How to add Property file
In the package explorer, right-click on the package and select New -> File, then enter the filename including the ".properties" suffix.How to create a 2D array in property file.
To do that you can use the following syntax.
ecf_providers=0,ECF Generic;1,r-OSGi;2,ecf.generic.server;3,ecf.filetransfer.bittorrent;\
4,ecf.msn.msnp;5,ecf.discovery.jslp;6,ecf.msn.msnp;7,ecf.xmpp.smack;
I have put "\" at the end of the first line to make sure that all the array data will be retrieved when the the method in the code uses the property file otherwise only the first line will be read form the property file. Another way to do is write the array as a single line like this.
ecf_providers=0,ECF Generic;1,r-OSGi;2,ecf.generic.server;3,ecf.filetransfer.bittorrent;4,ecf.msn.msnp;5,ecf.discovery.jslp;
Retrieve all 2D array data from Java properties file.
To get data from the property file and store it in a 2D array you can use the following two methods.
What this methods do is they one method read the data from the property file and the other method store that data in a array called Value_ecg_providers.
To read the data from the property file you can use a method like this.
private static String[][] fetchArrayFromPropFile(String propertyName,
Properties propFile) {
String[] a = propFile.getProperty(propertyName).split(";");
String[][] array = new String[a.length][a.length];
for (int i = 0; i < a.length; i++) {
array[i] = a[i].split(",");
}
return array;
}
try {
providers.load(RemoteServiceConsumerExample1Template.class
.getClassLoader().getResourceAsStream(
"providers.properties"));
Value_ecg_providers = fetchArrayFromPropFile("ecf_providers",
providers);
} catch (FileNotFoundException e) {
System.out.print("Property file not found");
e.printStackTrace();
} catch (IOException e) {
/
e.printStackTrace();
}
}
providers.load(RemoteServiceConsumerExample1Template.class
.getClassLoader().getResourceAsStream(
"providers.properties"));
Value_ecg_providers = fetchArrayFromPropFile("ecf_providers",
providers);
} catch (FileNotFoundException e) {
System.out.print("Property file not found");
e.printStackTrace();
} catch (IOException e) {
/
e.printStackTrace();
}
}
Great article and thanks for your work. putlockerss.pictures
ReplyDeletereally good article! you might as well want to check ufabet . Go to the website for more information
ReplyDeletemost romantic love story in hindi