我有这个问题。
我有以下方法:
public static Object[] czyDziala(String[] lista) throws IOException {
for(int i=0 ; i<=lista.length-1;i++){
URL url = new URL(lista[i]);
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
int len = httpCon.getContentLength();
if (len>0){
System.out.println(url +new String(" Site Work"));
}else{
System.out.println(url +"Site Don't Work");
}
}
return null;
}
方法中的参数是字符串列表。
JFrame okno = new JFrame();
okno.setSize(1200, 500);
okno.setVisible(true);
okno.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String [] col = {"Nazwa Witryny"};
String [] listaWitryn = {"http://www.wp.pl",
"http://www.onet.pl","http://mobidev.pl"};
try {
Work.czyDziala(listaWitryn);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
如何添加
表|网站名称|状态|
我认为创建错误的方法? 但我可能是错的。
答案 0 :(得分:0)
您的代码可能是:
public static Map<String, Boolean> czyDziala(String[] lista) throws IOException {
Map<String, Boolean> saveInDBList = new HashMap<String, Boolean>();
for(int i=0 ; i<=lista.length-1;i++){
URL url = new URL(lista[i]);
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
int len = httpCon.getContentLength();
if (len>0){
System.out.println(url +new String(" Site Work"));
saveInDBList.put(lista[i], true);
}else{
System.out.println(url +"Site Don't Work");
saveInDBList.put(lista[i], false);
}
}
return saveInDBList;
}
和
String [] col = {"Nazwa Witryny"};
String [] listaWitryn = {"http://www.wp.pl",
"http://www.onet.pl","http://mobidev.pl"};
try {
Map<String, Boolean> saveInDBList = Work.czyDziala(listaWitryn);
//Your Insert DB call
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}