我正在使用read line从维基百科获取一些文本。但是read line只返回列表,而不是我想要的文本。有没有办法使用替代方案或解决我的问题?
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);
}
}
}发布于 2011-06-03 04:12:44
BufferedReader实例definitely returns a String上的方法readLine()。在您的代码示例中,您在while循环中执行了两次readLine()。首先将其存储在inputLine中
while ((inputLine = in.readLine()) != null)然后在不检查它是否是null的情况下将(下一行)存储在TEST中。尝试将inputLine而不是TEST传递给render方法。
https://stackoverflow.com/questions/6219696
复制相似问题