On Feb 2, 2008, at 9:21 PM, Josh Paul wrote:

I'm attempting to read in a plist, alter some information, and then write it out again. My approach has been to read in the plist, convert it to a NSDictionary, alter the value of a given key, and then convert the dict back to a plist and write the file to disk. However, I am stuck on converting from NSDictionary to a plist.

        I think you're trying way too hard.

                try {
                        Object plist =
com .webobjects .foundation.NSPropertyListSerialization.propertyListWithPathURL(new java.net.URL("file:///Users/someuser/Desktop/test.plist"));

If the contents of test.plist is a string representation of a dictionary, then plist should be your dictionary. You may need to make a mutable copy to modify it (not sure).

                        NSMutableDictionary dict = 
((NSDictionary)plist).mutableClone();
                        dict.setObjectForKey("success", "Test");
                        String string =
com .webobjects .foundation.NSPropertyListSerialization.stringFromPropertyList(dict);

java.io.File outFile = new java.io.File("/Users/joshpaul/Desktop/ out.plist");
                        java.io.FileWriter out = new 
java.io.FileWriter(outFile);

                        out.write(string);

                } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } finally {
                          out.close();
                }


Aloha,
Art

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to