【发布时间】:2010-11-25 20:49:50
【问题描述】:
我正在遵循一个指南,它给了我以下代码:
InputSource inputSource = new InputSource(new FileInputStream(new File("/path/to/xml/file.xml"))));
我想知道的是,我如何仍然可以创建org.xml.sax.InputSource,但不是读取文件的内容,而是使用我已经拥有的String 变量。
【问题讨论】:
我正在遵循一个指南,它给了我以下代码:
InputSource inputSource = new InputSource(new FileInputStream(new File("/path/to/xml/file.xml"))));
我想知道的是,我如何仍然可以创建org.xml.sax.InputSource,但不是读取文件的内容,而是使用我已经拥有的String 变量。
【问题讨论】:
使用StringReader 而不是FileInputStream。
请参阅StringReader 的文档
示例:
InputSource inputSource = new InputSource( new StringReader( myString ) );
【讨论】:
InputSource inputSource = new InputSource(new java.io.StringReader(string)); 如果是org.xml.sax.InputSource。
【讨论】: