gpt4 book ai didi

java - Bufferedreader 返回 null

转载 作者:行者123 更新时间:2023-12-01 13:56:46 26 4
gpt4 key购买 nike

我正在尝试从文本中读取网址,然后让应用程序打开该地址,我的缓冲阅读器似乎正在正确读取行,但 readline 始终返回空

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();
}

关于java - Bufferedreader 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19582100/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com