输入流阅读器跳过一些文本
大家好,这是我的代码的一个发挥
public ItemList() throws Exception {
//itemList = new List<Item>() ;
List<Item> itemList = new ArrayList<Item>() ;
URL itemPhrases = new 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
}
我的问题是我正在尝试从 URL http://dl.dropbox.com/u/18678304/2011/BSc2/phrases.txt 但是当它打印出我收集的内容时,它只打印:
aaa
bbb
ddd
我尝试研究该库并使用调试器,但都没有帮助。
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 = new 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该从 while 循环内部删除
inputLine = in.readLine();
,它会再次调用readLine()
函数,从而跳过每一行。你的循环应该是这样的:
You should remove
inputLine = in.readLine();
from inside the while loop, it callsreadLine()
function a second time, thus skipping every second line.Your loop should look like this:
您连续调用
in.readLine()
两次。删除第二个调用。You are calling
in.readLine()
twice in a row. Remove the second call.