如何从字符串创建 org.xml.sax.InputSource? [英] How do I create an org.xml.sax.InputSource from a String?

查看:38
本文介绍了如何从字符串创建 org.xml.sax.InputSource?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遵循指南,它给了我以下代码:

I am following a guide, and it gives me the following code:

InputSource inputSource = new InputSource(new FileInputStream(new File("/path/to/xml/file.xml"))));

我想知道的是,我仍然可以创建 org.xml.sax.InputSource,但不是读取文件的内容,而是使用 String我已经拥有的变量.

What I would like to know, is how I can still create an org.xml.sax.InputSource, but instead of reading the content of a file, use a String variable that I already have.

推荐答案

使用 StringReader 而不是 FileInputStream.

请参阅StringReader

示例:

InputSource inputSource = new InputSource( new StringReader( myString ) );

这篇关于如何从字符串创建 org.xml.sax.InputSource?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆