Write a list of class FieldDescriptor to a file:
private static void saveFieldDefinitions(String fieldDescriptorName, LinkedList<FieldDescriptor> list) throws IOException {
XStream xs = new XStream();
xs.alias("FieldDescriptor", FieldDescriptor.class);
//Write
try {
FileOutputStream fs = new FileOutputStream(fieldDefinitionsFilePath + "\\" + fieldDescriptorName + ".xml");
xs.toXML(list, fs);
fs.close();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
}
Reada list of class FieldDescriptor from a file:
protected void loadFieldDefinitions(String fieldDescriptorName) {
XStream xs = new XStream(new DomDriver());
xs.alias("FieldDescriptor", FieldDescriptor.class);
//Read
try {
FileInputStream fs = new FileInputStream(fieldDefinitionsFilePath + "\\" + fieldDescriptorName + ".xml");
lstFieldDescriptor = (List<FieldDescriptor>) xs.fromXML(fs);
fs.close();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch(Exception e2) {
e2.printStackTrace();
}
}
No comments:
Post a Comment
Thank you for commenting!