.readLine() 的替代方案 / readLine 仅返回列表
我正在使用读取行从维基百科获取一些文本。但读取行仅返回列表,而不是我想要的文本。有什么方法可以使用替代方案或解决我的问题吗?
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);
}
}
}
I'm using read line to get some text from wikipedia. But read line only returns lists, not the text that I want. Is there any way to use an alternative or to solve my problem?
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);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
BufferedReader
实例上的方法readLine()
肯定返回一个字符串。在您的代码示例中,您在 while 循环中执行了两次 readLine() 。首先将其存储在inputLine
中:然后将(下行)存储在
TEST
中,而不检查它是否为null.尝试将
inputLine
而不是TEST
传递给render
方法。The method
readLine()
on aBufferedReader
instance definitely returns a String. In your code example, you are doing readLine() twice in your while loop. First you store it ininputLine
:Then you are storing (the next line) in
TEST
without checking if it isnull
. Try to passinputLine
instead ofTEST
to therender
method.