Java 如何从字符串创建org.xml.sax.InputSource?
我遵循一个指南,它给了我以下代码:Java 如何从字符串创建org.xml.sax.InputSource?,java,xml,Java,Xml,我遵循一个指南,它给了我以下代码: InputSource inputSource = new InputSource(new FileInputStream(new File("/path/to/xml/file.xml")))); 我想知道的是,我如何仍然可以创建一个org.xml.sax.InputSource,但不是读取文件的内容,而是使用我已有的字符串变量。使用StringReader而不是FileInputStream 有关详细信息,请参阅文档 例如: InputSource in
InputSource inputSource = new InputSource(new FileInputStream(new File("/path/to/xml/file.xml"))));
我想知道的是,我如何仍然可以创建一个
org.xml.sax.InputSource
,但不是读取文件的内容,而是使用我已有的字符串变量。使用StringReader
而不是FileInputStream
有关详细信息,请参阅文档
例如:
InputSource inputSource = new InputSource( new StringReader( myString ) );
InputSource-InputSource=newinputsource(newjava.io.StringReader(string))
如果是org.xml.sax.InputSource
的话,它就像一个魔咒。谢谢你,伙计。