plist to dict and back again
plist to dict and back again
- Subject: plist to dict and back again
- From: Josh Paul <email@hidden>
- Date: Sat, 2 Feb 2008 23:21:28 -0800
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. Sample:
try {
Object plist =
com
.webobjects
.foundation.NSPropertyListSerialization.propertyListWithPathURL(new
java.net.URL("file:///Users/someuser/Desktop/test.plist"));
String string =
com
.webobjects
.foundation.NSPropertyListSerialization.stringFromPropertyList(plist);
com.webobjects.foundation.NSDictionary dict =
com
.webobjects
.foundation.NSPropertyListSerialization.dictionaryForString(string);
dict.takeValueForKey("success", "Test");
log.debug(dict);
// ERROR occurs here...
plist =
com
.webobjects
.foundation
.NSPropertyListSerialization.propertyListFromString(dict.toString());
java.io.File outFile = new java.io.File("/Users/joshpaul/Desktop/
out.plist");
java.io.FileWriter out = new java.io.FileWriter(outFile);
out.write(dict.toString());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
out.close();
}
I know I'm reading in a valid plist, as it opens fine in Property List
Editor (and looks well formed in a text editor).
So, does anyone have any insight on how to accomplish this?
TIA.
_______________________________________________
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