我正在尝试从文本中读取网址,然后让应用打开该地址,我的缓冲读取器似乎正在正确读取行,但readline不断返回null
String rsslink = null;
InputStream is = getResources().openRawResource(R.raw.xmlsource);
BufferedReader br = new BufferedReader(new InputStreamReader(is));
try {
while ((rsslink = br.readLine()) != null)
{
}
}
catch (IOException e)
{
e.printStackTrace();
}
String RSS_LINK = rsslink;
Log.d(Constants.TAG, "Service started");
List<RssItem> rssItems = null;
try
{
XMLRssParser parser = new XMLRssParser();
rssItems = parser.parse(getInputStream(RSS_LINK));
最佳答案
您将获得最后一行null rsslink
。
你需要改变你的循环
try {
while ((rsslink = br.readLine()) != null)
{
}
}
至
try {
StringBuilder sb= new StringBuilder();
while ((rsslink = br.readLine()) != null)
{
sb.append(rsslink);
}
rsslink = sb.toString();
}