Java-BufferedReader未从url读取
我试着从45页都一样的页面(当然除了我正在读的部分)读出来,然后把它们写在一个行列表中 到目前为止,我编写了以下代码:Java-BufferedReader未从url读取,java,url,bufferedreader,Java,Url,Bufferedreader,我试着从45页都一样的页面(当然除了我正在读的部分)读出来,然后把它们写在一个行列表中 到目前为止,我编写了以下代码: public static ArrayList<ArrayList<String>> linesWeNeed(){ ArrayList<ArrayList<String>> returnListList = new ArrayList<ArrayList<String>>(); fo
public static ArrayList<ArrayList<String>> linesWeNeed(){
ArrayList<ArrayList<String>> returnListList = new ArrayList<ArrayList<String>>();
for(int i = 1; i<=45; i++){
int pageNum=(i*20)-20;
System.out.println("PageNum"+pageNum);
URL url=null;
try {
url = new URL("http://tq.mot.gov.il/index.php?option=com_moofaq&iotype=w&view=category&lang_ovrrde=ENG&id=3&Itemid=29&limitstart="+pageNum);
} catch (MalformedURLException e) {
System.out.println("Oh uh!");
}
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
} catch (IOException e) {
System.out.println("FATAL ERROR");
e.printStackTrace();
}
ArrayList<String> lineCodes = new ArrayList<String>();
ArrayList<String> linesWeNeed = new ArrayList<String>();
String line;
try {
readLines:
while((line=in.readLine())!=null){
if(line.contains("</tr></table></div></div></li></ul></div></div><br /></div>")){
break readLines;
}
lineCodes.add(line);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(int o = 1; o>=lineCodes.size(); o++){
String readLine = lineCodes.get(o-1);
if(o>=297){
linesWeNeed.add(readLine);
}
}
returnListList.add(linesWeNeed);
}
return returnListList;
}
publicstaticarraylistlinesweeneed(){
ArrayList returnListList=新建ArrayList();
对于(int i=1;i=lineCodes.size();o++){
String readLine=lineCodes.get(o-1);
如果(o>=297){
linesweeneed.add(readLine);
}
}
returnListList.add(linesweeneed);
}
返回列表;
}
没有错误,但由于某种原因,方法返回的arraylist中的每个列表都是空的。为什么?
提前谢谢
for(int o = 1; o>=lineCodes.size(); o++){
你的循环状态是从后向前的。尝试
你的循环状态是从后向前的。尝试
对于(int o=1;o>=lineCodes.size();o++){
仔细检查那里的循环条件;似乎该块永远不会执行
对于(int o=1;o>=lineCodes.size();o++){
仔细检查那里的循环条件;似乎该块永远不会执行