Android:使用 InputStream 打开位于 SD 中的文件时出现问题
我想用 XMLReader 解析位于 SD 中的 xml 文件
我有以下代码:
private RSSFeed getFeed(String urlToRssFeed)
{
try
{
// setup the url
URL url = new URL(urlToRssFeed);
// create the factory
SAXParserFactory factory = SAXParserFactory.newInstance();
// create a parser
SAXParser parser = factory.newSAXParser();
// create the reader (scanner)
XMLReader xmlreader = parser.getXMLReader();
// instantiate our handler
RSSHandler theRssHandler = new RSSHandler();
// assign our handler
xmlreader.setContentHandler(theRssHandler);
// get our data through the url class
InputSource is = new InputSource(url.openStream());
// perform the synchronous parse
xmlreader.parse(is);
// get the results - should be a fully populated RSSFeed instance,
// or null on error
return theRssHandler.getFeed();
}
catch (Exception ee)
{
// if you have a problem, simply return null
return null;
}
}
但这适用于在线 xml 文件 为了打开存储在 SD 卡中的 xml 文件,必须进行哪些更改?
I want to parse an xml file located in the SD with an XMLReader
I have this code:
private RSSFeed getFeed(String urlToRssFeed)
{
try
{
// setup the url
URL url = new URL(urlToRssFeed);
// create the factory
SAXParserFactory factory = SAXParserFactory.newInstance();
// create a parser
SAXParser parser = factory.newSAXParser();
// create the reader (scanner)
XMLReader xmlreader = parser.getXMLReader();
// instantiate our handler
RSSHandler theRssHandler = new RSSHandler();
// assign our handler
xmlreader.setContentHandler(theRssHandler);
// get our data through the url class
InputSource is = new InputSource(url.openStream());
// perform the synchronous parse
xmlreader.parse(is);
// get the results - should be a fully populated RSSFeed instance,
// or null on error
return theRssHandler.getFeed();
}
catch (Exception ee)
{
// if you have a problem, simply return null
return null;
}
}
but this works for on-line xml files
what changes must be done in order to open an xml file stored in the SD card?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否已将其添加
到清单文件中?
Have you added the
to your manifest file?