Alternative to .readLine() / readLine only returns lists
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);
}
}
}
The method readLine()
on a BufferedReader
instance definitely returns a String. In your code example, you are doing readLine() twice in your while loop. First you store it in inputLine
:
while ((inputLine = in.readLine()) != null)
Then you are storing (the next line) in TEST
without checking if it is null
. Try to pass inputLine
instead of TEST
to the render
method.
精彩评论