簡體   English   中英

從URL讀取並存儲在JAVA中的ArrayList中

[英]Reading from a URL and storing in an ArrayList in JAVA

我正在嘗試從下面的似乎有效的URL進行讀取,但是當我嘗試將其存儲在ArrayList中時,它給我一個錯誤。 關於導致錯誤的原因有什么想法?

public abstract class ItemList implements ItemListInterface{

private static String inputLine;
private static ArrayList<String> wordArray;

public static void main(String[] args) throws Exception {
    URL wordList = new URL("http://dl.dropbox.com/u/18678304/2011/BSc2/phrases.txt");
    BufferedReader in = new BufferedReader(
            new InputStreamReader(
                    wordList.openStream()));



    while ((inputLine = in.readLine()) != null){
        System.out.println(inputLine);
        wordArray.add(inputLine);
    }
    in.close();
   }
 }

您忘記實例化ArrayList<String>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM