Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2005

Tip: Looking for answers? Try searching our database.

problesm with compiling

Thread view: 
Gary Redmond - 12 Mar 2005 12:59 GMT
I am writing a program to store stuff to xml using the storeToXML method
but I can;t get it to compile here it is; any ideas?

import java.io.*;

import java.util.*;

public class XmlWrite {

    public static void main(String args[]) throws Exception {

        try {

            Properties props = new Properties();

            props.setProperty("something", "bla");

            props.setProperty("stuff", "brown and black");

            props.setProperty("morestuff", "me");

            props.setProperty("enablepassword", "yes");

            props.setProperty("answer", "null");

            String OperatingSystem = System.getProperty("user.home") +"\\";

            FileOutputStream xmlwrite =
            new FileOutputStream(OperatingSystem + "config.xml");

            props.java.util.Properties.storeToXML(xmlwrite, "config");

            xmlwrite.close();
        }

        // if writing to the specified output stream results in an
IOException

        catch (IOException e) {

            //Print system error

            System.err.println("An Error Occured While Writing To The
File");
        }

        //  if os is null.

        catch (NullPointerException e) {

            //Print system error

            System.err.println("OS Value is Null");

        }

    }

}
Piet - 13 Mar 2005 10:48 GMT
Hi Gary,
> I am writing a program to store stuff to xml using the storeToXML method
> but I can;t get it to compile here it is; any ideas?
First, I don´t believe that blank lines increase the readability of a
posting, but instead make it unneccessarily long. So you should think
of removing those blank lines the next time.
Second, a detailed description of the problem makes it much easier to
help. "Won´t work" or "Won´t compile" is generally not very
instructive.
> import java.io.*;
> import java.util.*;
[quoted text clipped - 4 lines]
>              Properties props = new Properties();
>              props.setProperty("something", "bla");
              //more properties
>              String OperatingSystem = System.getProperty("user.home") +"\\";
>              FileOutputStream xmlwrite =
>              new FileOutputStream(OperatingSystem + "config.xml");
>              props.java.util.Properties.storeToXML(xmlwrite, "config");
That won´t work. Your "props"-Object is an instance of
java.util.Properties, and the storeToXML method is consequently
invoked "props.storeToXML"
Note that the storeToXML and loadFromXML methods are only available in
Java 1.5. In Java 1.4 (the version that I still use) they are not
available.
For a comparison of the two versions:

http://java.sun.com/j2se/1.4.2/docs/api/java/util/Properties.html
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html
<rest of code omitted>
HTH
Piet


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.