Sorting the properties in java -
is there way sort properties object in java?
i have string groups properties , checks whether data available in map format.
please use example :
from link : http://www.java2s.com/tutorial/java/0140__collections/sortpropertieswhensaving.htm
import java.io.fileoutputstream; import java.util.collections; import java.util.enumeration; import java.util.properties; import java.util.vector; public class main{ public static void main(string[] args) throws exception { sortedproperties sp = new sortedproperties(); sp.put("b", "value b"); sp.put("c", "value c"); sp.put("a", "value a"); sp.put("d", "value d"); fileoutputstream fos = new fileoutputstream("sp.props"); sp.store(fos, "sorted props"); } } class sortedproperties extends properties { public enumeration keys() { enumeration keysenum = super.keys(); vector<string> keylist = new vector<string>(); while(keysenum.hasmoreelements()){ keylist.add((string)keysenum.nextelement()); } collections.sort(keylist); return keylist.elements(); } }
Comments
Post a Comment