Java.util.Properties methods load & store

Does java.util.Properties methods load & store produce & load platform independent code?

You mean that it is better to use loadFromXML(InputStream in) and storeToXML(OutputStream os, String comment) methods of this class in order to have platform independent code?

Similar Messages

  • Error in Parser.fx file "incompatible types found   : java.util.Properties"

    Hi,
    In parser file "Parser.fx",
    public-read def PROPERTIES_PARSER = StreamParser {
    override public function parse(input : java.io.InputStream) : RecordSet {
    var props = javafx.util.Properties {};
    props.load(input);
    input.close();
    MemoryRecordSet {
    records: [
    MapRecord {
    fields: props
    due to under line portion an error is appearing:
    "incompatible types
    found : javafx.util.Properties
    required: java.util.Map
    fields: props".
    Please suggest some solution.
    Thanks in advance.
    regards,
    Choudhary Nafees Ahmed
    Edited by: ChoudharyNafees on Jul 5, 2010 3:48 AM

    Parser.fx
    package org.netbeans.javafx.datasrc;
    import javafx.data.pull.PullParser;
    import javafx.data.pull.Event;
    import org.netbeans.javafx.datasrc.MemoryRecordSet;
    public-read def PROPERTIES_PARSER = StreamParser {
        override public function parse(input : java.io.InputStream) : RecordSet {
            var props =java.util.Properties{};
            props.load(input);
            input.close();
            MemoryRecordSet {
                records: [
                    MapRecord {
                        fields: props
    public-read def LINE_PARSER_FIELD_LINE = ".line";
    public-read def LINE_PARSER = StreamParser {
        override public function parse(input : java.io.Reader) : RecordSet {
            var line : String;
            var result : Record [] = [];
            line = readLine(input);
            // BEWARE  ("" == null) is true
            while (line != null or "".equals(line)) {
                var map = new java.util.HashMap();
                map.put(LINE_PARSER_FIELD_LINE, line);
                var record = MapRecord {
                    fields: map
                insert record into result;
                line = readLine(input);
            MemoryRecordSet {
                records: result
    function readLine(in : java.io.Reader) : String {
        var str = new java.lang.StringBuilder;
        while (true) {
            var c = in.read();
            if (c == -1) {
                return if (str.length() == 0) then null else str.toString();
            } else if (c == 0x0D) {
                c = in.read();
                if (c == 0x0A or c == -1) {
                    return str.toString();
                str.append(0x0D);
            } else if (c == 0x0A) {
                return str.toString();
            str.append(c as Character);
        str.toString()
    public-read def JSON_PARSER = StreamParser {
        function toSequence(list : java.util.List) : Record [] {
            var result : Record [] = [];
            var ii = list.iterator();
            while (ii.hasNext()) {
                var r = ii.next() as Record;
                insert r into result;
            result
        override public function parse(input : java.io.InputStream) : RecordSet {
            var topLevel : Object;
            def parser = PullParser {
                documentType: PullParser.JSON
                input: input
                var mapStack = new java.util.Stack();
                var currentMap : java.util.Map;
                var recordsStack = new java.util.Stack();
                var currentRecords : java.util.List;
                var lastEvent: Event;
                onEvent: function(event: Event) {
                    if (event.type == PullParser.TEXT) {
                        currentMap.put(event.name, event.text)
                    } else if (event.type == PullParser.INTEGER) {
                        currentMap.put(event.name, event.integerValue)
                    } else if (event.type == PullParser.NULL) {
                        currentMap.put(event.name, null)
                    } else if (event.type == PullParser.START_ELEMENT) {
                        if (lastEvent.type == PullParser.START_ARRAY_ELEMENT) return;
                        var oldMap = currentMap;
                        var temp = new java.util.HashMap();
                        temp.put(new Object(), null);
                        currentMap = temp;
                        currentMap.clear();
                        mapStack.push(currentMap);
                        if (topLevel == null) topLevel = currentMap;
                        if (oldMap != null) {
                            var mr = MapRecord {
                                fields: currentMap
                            if (event.name == "" and lastEvent.type == PullParser.START_VALUE) {
                                oldMap.put(lastEvent.name, mr)
                            } else {
                                oldMap.put(event.name, mr)
                    } else if (event.type == PullParser.START_ARRAY_ELEMENT) {
                        var temp = new java.util.HashMap();
                        temp.put(new Object(), null);
                        currentMap = temp;
                        currentMap.clear();
                        mapStack.push(currentMap);
                        var mr = MapRecord {
                            fields: currentMap
                        currentRecords.add(mr);
                    } else if (event.type == PullParser.END_ELEMENT) {
                        mapStack.pop();
                        if (not mapStack.empty()) {
                            currentMap = mapStack.peek() as java.util.HashMap;
                        } else {
                            currentMap = null;
                    } else if (event.type == PullParser.END_ARRAY_ELEMENT) {
                        if (lastEvent.type == PullParser.END_ELEMENT) return;
                        mapStack.pop();
                        if (not mapStack.empty()) {
                            currentMap = mapStack.peek() as java.util.HashMap;
                        } else {
                            currentMap = null;
                    } else if (event.type == PullParser.START_ARRAY) {
                        currentRecords = new java.util.ArrayList();
                        recordsStack.push(currentRecords);
                        if (topLevel == null) topLevel = currentRecords;
                    } else if (event.type == PullParser.END_ARRAY) {
                        var set = MemoryRecordSet {
                            records: toSequence(currentRecords)
                        currentMap.put(event.name, set);
                        recordsStack.pop();
                        if (not recordsStack.empty()) {
                            currentRecords = recordsStack.peek() as java.util.List;
                        } else {
                            currentRecords = null;
                    lastEvent = event;
            parser.parse();
            if (topLevel instanceof java.util.Map) {
                var mr = MapRecord {
                    fields: topLevel as java.util.Map
                MemoryRecordSet {
                   records: [mr]
            } else {
                // List
                var rs = MemoryRecordSet {
                    records: toSequence(topLevel as java.util.List)
                rs
            parser.parse();
            var mr = MapRecord {
                fields: topLevel as java.util.Map
            MemoryRecordSet {
               records: [mr]

  • Java.util.properties ? Using Config.getProperty

    Hi all,
    This one has been causing me a bit of a headache! I am using the Java.util.properties to create a file which looks like this:
    #Tue Sep 13 19:15:06 GMT+02:00 2002
    User=tristan
    Password=bristol
    Name=Tristan\ Webb
    Rights=Tristan\ Webb
    #Tue Sep 13 19:15:35 GMT+02:00 2002
    User=adam
    Password=newcastle
    Name=Adam\ Jones
    Rights=Adam\ Jones
    The problem comes when I try to read the information back and put it in a Vector. Using the code below, it only ever puts the last users details (i.e. adam, Newcastle etc..) into the file and skips the first one. I have tried adding more users details, but it only ever reads the last entry. Is there anyway of forcing the config.getProperty to read the first entry in the file and then all the subsequesnt user details ?? I am thinking there must be a way of looping through the file, but im not sure where to start and am quite lost!
    Many Thanks,
    Properties config;
    FileInputStream file;
    file = new FileInputStream("password.cfg");
    config = new Properties();
    config.load(file);
    User2 = config.getProperty("User");
    Password = config.getProperty("Password");
    name = config.getProperty("Name");
    rights = config.getProperty("Rights");
    UserDetails user = new UserDetails(User2, Password, name, rights);
    userDetails.add(user);

    The java.util.Properties class works like a dictionary: it stores values, which you can access using the keys.
    The keys must be unique. In your case, the keys are not unique. If you do: String s = config.getProperty("User"); then how do you expect to get two values back (tristan and adam)?
    You must make the keys unique in some way. For example, write your properties file like this:
    #Tue Sep 13 19:15:06 GMT+02:00 2002
    User.1=tristan
    Password=.1bristol
    Name.1=Tristan\ Webb
    Rights.1=Tristan\ Webb
    #Tue Sep 13 19:15:35 GMT+02:00 2002
    User.2=adam
    Password.2=newcastle
    Name.2=Adam\ Jones
    Rights.2=Adam\ Jones
    Now use for example: String s = config.getProperty("User.1"); to get the name of the first user, etc.
    Jesper

  • Applet using java.util.Properties.setPropterty()

    Hi,
    I'm trying to use the java.util.Properties class in an Applet. More specifically the setProperty(String, String) method. My applet compiles fine but it crashes when I run it with IE (ver. 6). It shows an "NoSuchMethodError: method setProperty(Ljava.lang.String,Ljava.lang.String)". When I compile with javac, it doesn't complain but I guess the IE VM doesn't see that method. But Properties is part of java.util.*, so shouldn't IE have access to that class?
    Any help is much appreciated?
    Thanks
    Heather

    The API for that method includes this:
    Since:
    1.2
    That means it's a Java 2 method. The JVM in Internet Explorer doesn't support Java 2 methods (unless you load a plugin that does).

  • Finding the key according to string length in java.util.Properties

    Finding the key according to string length in java.util.Properties.
    I know only String length only.

    i need to retrieve the values from the java.util.properties.
    we know that we need to give the key value in order to retrieve the datas.
    but my problem is i will give the length of the key instead of giving the key value but i need to retrieve the datas according to the length of the key.

  • Java.lang.NoSuchMethodError: java/util/Vector method revove...

    After using jexegen from microsoft to make EXE. I receive this error when i execute the my EXE :
    java.lang.NoSuchMethodError: java/util/Vector method revove...
    Any body know why?
    If i execute from JBuilder i have no problem!

    hi, i don't have much experience with M$ java products, but as far as i remember, M$ java stopped developping since jdk 1.1.4 (or 1.1.7).
    maybe that's the reason for throwing this exception. if you want to "exe" your class-file, try JToExe.
    greetzzz
    chris

  • Retrofitting java.util.Properties

    Hi all,
    why was java.util.Properties in JDK 1.5 not retrofitted to implement java.util.Map<String,String>?
    This would have been the "natural" way to take advantage of typesafety.
    I'm sure this has something to do with backwards compatibility, but what exactly woud it break?
    Thanks

    java.util.Properties extends java.util.Hashtable
    java.util.Properties : private java.util.HashtableWhat does that actually buy you though?
    I mean its really the difference between:
    class Properties {
        final Hashtable m_contents = new Hashtable();
        public String getProperty(String key) {
                return (String) m_contents.get(key);
    }vs.
    class Properties private extends Hashtable {
        public String getProperty(String key) {
                return (String) super.get(key);
    }Which is nice and all, but it strikes me as syntactic sugar more than anything else.
    I don't disagree: Properties should never have extended Hashtable, it should have encapsulated a Hashtable. Also Stack should not extend Vector, Booleans should not have a public constructor, it would even have been nicer if people actually used the Dictionary interface occassionally in 1.0/1.1.
    Its easy to say these things now with the benefit of 20-20 hindsight.

  • Invalid data returned when iterating a java.util.Properties

    Hi all,
    I'm having trouble iterating thru the values in a java.util.Properties object.
    This problem only occurs when passing in a java.util.Properties object into the constructor of a java.util.Properties.
    Here's some example code. (A picture is worth....)
    <pre>
    import java.util.Properties;
    import java.util.Iterator;
    public class PropertyTest {
    public static void main(String[] args) {
    Properties validProp = new Properties();
    //add some data
    validProp.put("key1", "key1Value");
    validProp.put("key2", "key2Value");
    validProp.put("key3", "key3Value");
    System.out.println("This will iterate...");
    dumpPropertyFile(validProp); //This will iterate correctly
    Properties inValidProp = new Properties(validProp);
    System.out.println("This doesn't iterate correctly");
    dumpPropertyFile(inValidProp); //This will not iterate
    public static void dumpPropertyFile(Properties prop) {
    Iterator iter = prop.keySet().iterator();
    while (iter.hasNext()) {
    String key = (String)iter.next();
    System.out.println(key + "=" + prop.getProperty(key));
    </pre>
    I have searched the bug database, but didn't find any open bugs related to this issue.
    Could someone let me know if this is a existing bug or has this bug already been addressed.
    My setup.
    NT 4.0 / jdk1.3.1
    Thanks,

    I found this works.
    Iterator e = _props.keySet().iterator();
    while(e.hasNext())
    String str = (String)e.next();
    System.out.println("key(" + str + ")=" + _props.getProperty(str));
    but the display sequence is always in descending order ???
    Anyone has a clue ?
    Input :
    catch#2 Prop catch#2
    prop2 Properties.test.2
    catch#6 Prop catch#6
    catch#3 Prop catch#3
    catch#5 Prop catch#5
    catch#4 Prop catch#4
    prop3 test Properties
    prop4 test Properties4
    prop1 Properties.test.1
    catch#1 Prop catch#1
    Output:
    prop4=test Properties4<
    prop3=test Properties<
    prop2=Properties.test.2<
    prop1=Properties.test.1<
    catch#6=Prop catch#6<
    catch#5=Prop catch#5<
    catch#4=Prop catch#4<
    catch#3=Prop catch#3<
    catch#2=Prop catch#2<
    catch#1=Prop catch#1<

  • Unable to validate a java.util.Properties XML based File

    I cannot for the life of me figure out what is wrong with this xml file, but it fails the validation of java.util.Properties and as such won't be parsed in. Help!
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
    <properties version="1.0">
      <entry key="bottleneckServer.address"></entry>
      <entry key="bottleneckServer.port">8206</entry>
      <entry key="bottleneckServer.confirmDelay">10</entry>
      <entry key="bottleneckServer.cleanupDelay">120</entry>
    </properties>Thanks in advance!

    This xml file works perfectly.
    Here is some test code:
            Properties p = new Properties();
            p.loadFromXML(getClass().getClassLoader().getResourceAsStream("someFilePath/someFileName.xml"));
            assert "8206".equals(p.getProperty("bottleneckServer.port")) : "Property 'bottleneckServer.port' != 8206";

  • Java.sql.Date and java.util.Date - class loaded first in the classpath

    I had two jar files which has java.util.Date and java.sql.Date class file. i want to know whether which class is loaded first in the classpath...
    I like to change the order of loading the class at runtime...
    Is there is any way to change the order of loading of class...
    I may have different version of jar files for example xerces,xercesImpl. some of the code uses xerces ,some of the code uses xercesImpl..i had common classes.
    I like to load the class with the same name according to the order i need..
    Can we do all these in Run time ?????

    I had two jar files which has java.util.Date and
    java.sql.Date class file. i want to know whether
    which class is loaded first in the classpath...
    I like to change the order of loading the class at
    runtime...
    Is there is any way to change the order of loading of
    class...
    I may have different version of jar files for example
    xerces,xercesImpl. some of the code uses xerces ,some
    of the code uses xercesImpl..i had common classes.
    I like to load the class with the same name according
    to the order i need..
    Can we do all these in Run time ?????That is meaningless.
    The classes you are referring to are part of the Java API. Third party jars have no impact on that. And you can't change to the order because java.sql.Data is derived from java.util.Date. So the second must load before the first.
    And if you have two jar files with those classes in them (and not classes that use them) then you either should already know how to use them or you should stop trying to do whatever you are doing because it isn't going to work.

  • Java.util.Arrays; (method sort( ) )

    1) How to change a direction of sorting (on increase / on decrease)?
    2) Whether exists in java 2 something similar for sorting Strings ?

    1) How to change a direction of sorting (on increase
    / on decrease)?[url http://java.sun.com/j2se/1.5.0/docs/api/java/util/Collections.html#reverseOrder()]http://java.sun.com/j2se/1.5.0/docs/api/java/util/Collections.html#reverseOrder()
    2) Whether exists in java 2 something similar for
    sorting Strings ?Arrays.sort and Collections.sort will both sort the array or list as long as the type implements Comparable (or you supply a separate Comparator). Since String implements Comparable, those sort methods will sort the array or list of strings.
    Making Java Objects Comparable
    http://java.sun.com/docs/books/tutorial/collections/interfaces/order.html
    http://www.javaworld.com/javaworld/jw-12-2002/jw-1227-sort.html

  • Error HTTP Status 500 - while trying to invoke the method java.util.Properties.entrySet() of a null object loaded from local variable 'globalProperties'

    Hi,
    I installed BI platform SBOP BI PLAT 4.1 and was able to log in to CMC and BI Launchpad. Post this, I installed SBOP DATA SERVICES 4.2 SP01 PATCH 3 WINDOWS 64B and am getting the above error while trying to open CMC and BI Launchpad.
    Please help

    Thanks Jawahar, re deploying web apps helped.

  • Java.util.Properties.load() not loading all properties

    Hi,
    I'm trying to load the following properties into my Properties class. However, Im only able to load SOME properties not ALL (11 to be precise)
    This is my properties file :
    ~~~~~~~~~~~~~~~~~~~~~
    gds.host=chissd235.bankofamerica.com
    gds.datasource=gds.310.fob1
    its.dataSource=gds.310.fob1
    adv.dataSource=adv.310.fob1
    gds.port=9650
    gds.dataType=FpML
    maxNumberOfConnectors=1000
    itsConnectionMethod=ejb
    advDB.driverToUse=jConnect2
    advDB.userName=advDev1User
    advDB.password=advDev1User
    advDB.databaseName=advDev1
    advDB.serverName=chisdd30.bankofamerica.com
    advDB.port=2910
    its.user=derivuser
    This is my java code snippet:
    ~~~~~~~~~~~~~~~~~~~~~~~
         private void loadProperties()
              try
                   GDSConfigurationAdapter adapter = new GDSConfigurationAdapter();
                   String configurationResource = adapter.getConfigurationPropertiesResource();
                   load(loadStream(configurationResource));
                   String eventingPropsResource = adapter.getEventingPropertiesResource();
                   load(loadStream(eventingPropsResource));
              } catch (IOException e)
                   throw new RuntimeException("Could not load GDS/Eventing properties");
         private InputStream loadStream(String propFile) throws IOException
    InputStream propStream = ResourceLocator.getResourceAsStream(propFile);
    if (propStream == null)
    logger.warning("could not find in JAR! Looking in classpath: " + propFile);
    propStream = ResourceLocator.getResourceAsStream(propFile);
    if (propStream == null)
    IOException t = new IOException("Failed to load property file: " + propFile);
    logger.throwing(getClass().getName(), "loadProperties", t);
    throw t;
    return propStream;
    Any help will be appreciated.
    Thanks
    Bjork

    Hi,
    I'm trying to load the following properties into my Properties class. However, Im only able to load SOME properties not ALL (11 to be precise)
    This is my properties file :
    ~~~~~~~~~~~~~~~~~~~~~
    gds.host=chissd235.bankofamerica.com
    gds.datasource=gds.310.fob1
    its.dataSource=gds.310.fob1
    adv.dataSource=adv.310.fob1
    gds.port=9650
    gds.dataType=FpML
    maxNumberOfConnectors=1000
    itsConnectionMethod=ejb
    advDB.driverToUse=jConnect2
    advDB.userName=advDev1User
    advDB.password=advDev1User
    advDB.databaseName=advDev1
    advDB.serverName=chisdd30.bankofamerica.com
    advDB.port=2910
    its.user=derivuser
    This is my java code snippet:
    ~~~~~~~~~~~~~~~~~~~~~~~
         private void loadProperties()
              try
                   GDSConfigurationAdapter adapter = new GDSConfigurationAdapter();
                   String configurationResource = adapter.getConfigurationPropertiesResource();
                   load(loadStream(configurationResource));
                   String eventingPropsResource = adapter.getEventingPropertiesResource();
                   load(loadStream(eventingPropsResource));
              } catch (IOException e)
                   throw new RuntimeException("Could not load GDS/Eventing properties");
         private InputStream loadStream(String propFile) throws IOException
    InputStream propStream = ResourceLocator.getResourceAsStream(propFile);
    if (propStream == null)
    logger.warning("could not find in JAR! Looking in classpath: " + propFile);
    propStream = ResourceLocator.getResourceAsStream(propFile);
    if (propStream == null)
    IOException t = new IOException("Failed to load property file: " + propFile);
    logger.throwing(getClass().getName(), "loadProperties", t);
    throw t;
    return propStream;
    Any help will be appreciated.
    Thanks
    Bjork

  • Java.util.Properties

    I execute this piece of code on application startup
    public final Properties loadProperties() throws VmsBaseException {
    Properties prop = new Properties();
    prop.setProperty("ei.properties.file.import.path", "C:/projects/folders/input");
    prop.setProperty("ei.properties.file.output.path", "C:/projects/folders/output");
    prop.setProperty("ei.properties.file.name.pattern", "*.xml");
    prop.setProperty("ei.properties.fixed.delay", "6000");
    prop.setProperty("ei.properties.file.poller.interval", "100");
    prop.setProperty("ei.properties.file.archive.path", "C:/projects/folders/archiveFolder/");
    prop.setProperty("ei.properties.file.error.path", "C:/projects/folders/errorFolder/");
    return prop;
    Later on I would like my other beans to get hold of this properties and use the value inside it.
    Any Idea how to achieve it

    Manjit wrote:
    Later on I would like my other beans to get hold of this properties and use the value inside it.
    Any Idea how to achieve itYes, put the properties object somewhere where you can always reach it. Either that or let any piece of code that needs it call your loadProperties() method.
    I'm sorry but your question is very open ended, so it is nearly impossible to be more specific.

  • Java.util.Properties issue

    I have an Integer array that i want to store using properties.
    At the moment i have something like this
    for(int i = 0; i < guitarNo.length; i++)     {
         p.setProperty("Identification", Integer.toString(guitarNo));
    }But it doesn't store any of the ids it simpily stores as 1
    Anyhelp would be fantastic                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    bulger2503 wrote:
    Ah well thats an inconvenience :)
    Could you suggest another way?Maybe you could build a Properties file like the following given an e.g guitarNo like { 21, 54, 41 }
    guitarNo          = 3
    Id0               = 21
    Id1               = 54
    Id2               = 41When you have to read the values back again, first read the key "guitarNo", create your array and read the keys "Id"+i for i in in [0,3)
    kind regards,
    Jos

Maybe you are looking for

  • What are the Connectors available for KM file repository?

    Hi All, Which are different connectors available for KM? Apart from below list      Windows File Server      Web Servers (HTTP)      WebDAV compliant servers (MS Sharepoint, MS Exchange Public Folders, LiveLink)      mySAP PLM DMS      SAP Knowl

  • Itunes reopens after quit

    Hello, brand new on the forum/discussions. It is really annoying whenever I quit iTunes, it automatically opens itself again. I then wait, quit it again and then goes away. Not really demanding answers, but wanted to let the main guys know about this

  • Including image in xml

    hi all, Dont get angry for asking this silly question.I m new for XML. I have an image that is in jar file ,i want to display that image in an XML page. What problem occurs is when i run the jar file ,XML and XSL files created in C drive. But the ima

  • Adobe After Effects problem

    Hi I have a problem with After effects cs4 in windows 7 64-bit , I just installed everyting on a new computer core i7 860 , seagate 1TB etc , graphic-card nivida asus engtx275. When I import film-material and move the timeslider the viewport seems ve

  • Unable to process payload greater than 20MB

    We have a SOA system,in which a third party system hits the end point URI exposed by proxy service in OSB. Initially it holds good for 10MB of payload size. After a while we need to process payloads greater than 10MB. In such situation we did some co