2011-06-02 145 views
1

我正在使用read line从维基百科获取一些文本。但读线只返回列表,而不是我想要的文本。有没有办法使用替代方案或解决我的问题?.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); 
     } 
    } 
} 
+0

你是什么意思'readline只返回列表'?阅读行会为读者遇到的每一行返回一个字符串。 – Joseph 2011-06-02 20:10:51

+0

你的'PlainTextConverter'和你的'WikiModel'是什么?这些不是标准平台的一部分。 – 2011-06-02 20:58:29

回答

2

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

while ((inputLine = in.readLine()) != null) 

那么你在TEST存储(在下一个线)不检查,如果它是null。尝试将inputLine而不是TEST传递给render方法。