Re: plist to dict and back again
Re: plist to dict and back again
- Subject: Re: plist to dict and back again
- From: Art Isbell <email@hidden>
- Date: Sat, 2 Feb 2008 23:15:21 -1000
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@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden