第三方方法将XML输出到终端。如何将其重定向到SAX解析器可读的流?我正在尝试这样的事情:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
System.setOut(ps);
client.response(); //prints to terminal
System.out.flush();
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
... define handler ...
saxParser.parse(baos,handler);
但是,由于最后一行不起作用,我一直希望这样:
InputStream xmlInput = new InputStream(baos);
saxParser.parse(xmlInput,handler);
答案 0 :(得分:1)
InputStream xmlInput = new ByteArrayInputStream(baos.toByteArray());