首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >.readLine() / readLine的替代方法仅返回列表

.readLine() / readLine的替代方法仅返回列表
EN

Stack Overflow用户
提问于 2011-06-03 03:59:14
回答 1查看 2.1K关注 0票数 1

我正在使用read line从维基百科获取一些文本。但是read line只返回列表,而不是我想要的文本。有没有办法使用替代方案或解决我的问题?

代码语言:javascript
复制
public class mediawiki {

    public static void main(String[] args) throws Exception {
        URL yahoo = new URL(
            "http://en.wikipedia.org/w/index.php?title=Jesus&action=raw"
        );
        BufferedReader in = new BufferedReader(
            new InputStreamReader(yahoo.openStream())
        );
        String inputLine;       

        //http://en.wikipedia.org/w/index.php?title=Space&action=raw

        while ((inputLine = in.readLine()) != null) {
            String TEST = in.readLine();

            //while ((inputLine = in.readLine()) != null)
            //System.out.println(inputLine);
            //This basicly reads each line, using
            //the read line command to progress

            WikiModel wikiModel = new WikiModel(
                "http://www.mywiki.com/wiki/${image}",
                "http://www.mywiki.com/wiki/${title}"
            );
            String plainStr = wikiModel.render(
                new PlainTextConverter(),
                TEST
            );
            System.out.print(plainStr);
        }
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-06-03 04:12:44

BufferedReader实例definitely returns a String上的方法readLine()。在您的代码示例中,您在while循环中执行了两次readLine()。首先将其存储在inputLine

代码语言:javascript
复制
while ((inputLine = in.readLine()) != null)

然后在不检查它是否是null的情况下将(下一行)存储在TEST中。尝试将inputLine而不是TEST传递给render方法。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6219696

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档