C# jaxb封送处理生成空文件

C# jaxb封送处理生成空文件,c#,java,xml,jaxb,C#,Java,Xml,Jaxb,正在尝试封送IIS/java 1.6上运行的kml文件。jaxb封送器没有抛出错误。文件已创建,但未写入任何内容。在1.6上运行jaxb是否存在问题 final Kml __balloonKML = new Kml(); final de.micromata.opengis.kml.v_2_2_0.Document baloonDocument =__balloonKML.createAndSetDocument(); OutputStream o = new FileOut

正在尝试封送IIS/java 1.6上运行的kml文件。jaxb封送器没有抛出错误。文件已创建,但未写入任何内容。在1.6上运行jaxb是否存在问题

final Kml __balloonKML = new Kml();
        final de.micromata.opengis.kml.v_2_2_0.Document baloonDocument =__balloonKML.createAndSetDocument();

 OutputStream o = new FileOutputStream("test.kml");
                 try
                    {
                // __balloonKML.marshal(o);
                    Marshaller m = createMarshaller();
                    m.marshal(__balloonKML, o);
                            o.flush(); o.close();
                    }
                    catch (JAXBException _x)
                    {
                      _x.printStackTrace();
                    }

private JAXBContext getJaxbContext()
            throws JAXBException
          {
        JAXBContext jc = null;

              jc = JAXBContext.newInstance(new Class[] { Kml.class });

            return jc;
          }

     private Marshaller createMarshaller()
                throws JAXBException
              {
                Marshaller m = null;
                  m = getJaxbContext().createMarshaller();
                  m.setProperty("jaxb.formatted.output", Boolean.valueOf(true));
                  m.setProperty("com.sun.xml.bind.namespacePrefixMapper", true);
                return m;
              }
使用文件的其他方法不起作用

 File file = new File(kmlLoc+"//kml//baloonLayer"+msgId+".kml");
                 JAXBContext jaxbContext = JAXBContext.newInstance(Kml.class);
                 Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
                 jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
                 jaxbMarshaller.marshal(__balloonKML, file);
确保将
输出流编组到
后刷新()/close(
flush()
/
close()
)输出流

演示

当我运行稍微修改过的代码版本(见下文)时,我会得到一个包含生成内容的文件

import java.io.*;
import javax.xml.bind.*;

public class Demo {

    public static void main(String[] args) throws Exception {
        Demo demo = new Demo();
        demo.marshal();
    }

    private void marshal() throws Exception {
        final Kml __balloonKML = new Kml();
        //final de.micromata.opengis.kml.v_2_2_0.Document baloonDocument = __balloonKML.createAndSetDocument();

        OutputStream o = new FileOutputStream("test.kml");
        try {
            // __balloonKML.marshal(o);
            Marshaller m = createMarshaller();
            m.marshal(__balloonKML, o);
            //o.flush();
            o.close();
        } catch (JAXBException _x) {
            _x.printStackTrace();
        }
    }

    private JAXBContext getJaxbContext() throws JAXBException {
        JAXBContext jc = null;

        jc = JAXBContext.newInstance(new Class[] { Kml.class });

        return jc;
    }

    private Marshaller createMarshaller() throws JAXBException {
        Marshaller m = null;
        m = getJaxbContext().createMarshaller();
        //m.setProperty("jaxb.formatted.output", Boolean.valueOf(true));
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        //m.setProperty("com.sun.xml.bind.namespacePrefixMapper", true);
        return m;
    }
}
输出文件(test.kml)


返回false是什么意思?我看不到任何返回布尔值的东西。不相关,但是如果(jc==null)
从上面看它总是空的,这有点多余。还有布尔值。。只需使用
Boolean.TRUE
我很抱歉,false是从另一个类中抛出的,但这已经被排除了。Jaxb.marshal只是在生成一个空文件…而
\uuu2u0.kmlTanks的外观如何,请显示作为JAK-kml的一部分的kml类,de.micromata.opengis.kml.v_2_2_0.kmlTanks以供评论。但是,添加后文件大小仍然为0。@user3032973-尝试刷新。@user3032973-是否尝试编组到
文件
?不确定如何执行。我有一个de.micromata.opengis.kml.v_2_2_0.kml和de.micromata.opengis.kml.v_2_2_0.Document对象。有人能解决这个问题吗?
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<kml/>
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class Kml {

}