开发者

Inputstream reader skips over some text

Hi guys so this is an exert from the code I have

public ItemList() throws Exception {
    //itemList = new List<Item>() ;
    List<Item> itemList = new ArrayList<Item>() ;

    URL itemPhrases = n开发者_StackOverflow中文版ew URL("http://dl.dropbox.com/u/18678304/2011/BSc2/phrases.txt");     // Initilize URL
    BufferedReader in = new BufferedReader(new InputStreamReader(
            itemPhrases.openStream())); // opens Stream from html

    while ((inputLine = in.readLine()) != null) {
        inputLine = in.readLine();
        System.out.println(inputLine);
        Item x = new Item(inputLine);
        itemList.add(x);
    } // validates and reads in list of phrases
    for(Item item: itemList){ 
        System.out.println(item.getItem());
    }

    in.close();// ends input stream
}

My problem is that I am trying to read in a list of phrases from the URL http://dl.dropbox.com/u/18678304/2011/BSc2/phrases.txt but when it prints out what I have collected it just prints:

aaa

bbb

ddd

I have tried researching the library and using the debugger but neither have helped.


You should remove inputLine = in.readLine(); from inside the while loop, it calls readLine() function a second time, thus skipping every second line.

Your loop should look like this:

while ((inputLine = in.readLine()) != null) {
        //this line must not be here inputLine = in.readLine();
        System.out.println(inputLine);
        Item x = new Item(inputLine);
        itemList.add(x);
    }


You are calling in.readLine() twice in a row. Remove the second call.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜