小编And*_*ndy的帖子

导出为 XML,包括嵌入类

我有一个具有一些属性的对象配置。我可以导出这个,但是,它还有一个与嵌入类相关的 ArrayList,当我导出到 XML 时,我无法显示该类。任何指示都会有帮助。

导出方式

public String exportXML(config conf, String path) {
    String success = "";
    try {
        FileOutputStream fstream = new FileOutputStream(path);
        try {
            XMLEncoder ostream = new XMLEncoder(fstream);
            try {
                ostream.writeObject(conf);
                ostream.flush();
            } finally {
                ostream.close();
            }
        } finally {
            fstream.close();
        }
    } catch (Exception ex) {
        success = ex.getLocalizedMessage();
    }
    return success;
}
Run Code Online (Sandbox Code Playgroud)

配置类 (为了缩小尺寸而删除了一些细节)

public class config {

protected String author = "";
protected String website = "";
private ArrayList questions = new ArrayList(); …
Run Code Online (Sandbox Code Playgroud)

java xml xml-serialization

5
推荐指数
1
解决办法
2201
查看次数

标签 统计

java ×1

xml ×1

xml-serialization ×1