2011-06-02 146 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方法。