我想將生成的模式輸出到標準輸出。所以我將System.out設置爲SchemaOutputResolver的outputStream。 StreamResult result = new StreamResult(System.out);
但會後聲明: jc.generateSchema(outputResolver)
如何避免System.out從回調中關閉
的System.out.println()不工作了。通過調試我得到的代碼後,System.out在jc.generateSchema
方法後關閉。
JAXBContext jc = JAXBContext.newInstance(SomeObject.class);
SchemaOutputResolver outputResolver = new SchemaOutputResolver() {
@Override
public Result createOutput(String namespaceUri, String suggestedFileName)
throws IOException {
StreamResult result = new StreamResult(System.out);
result.setSystemId(namespaceUri);
// return result
return result;
}
};
jc.generateSchema(outputResolver);
System.out.println("this String can't be output");
我的問題是,如何將所生成的模式,而不使用jc.generateSchema
關閉的System.out到標準輸出?
謝謝,這正是我想要的。我寫了一些類似的類,但不知道如何將System.out分配給wrap類。 :)謝謝你的好代碼。 –