如果我尝试读取空白网页,我将如何返回默认字符串?
private void setVersion(String input) {
try {
URL url = new URL(input);
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String getInfo;
while ((getInfo = in.readLine()) != null) {
Console("[setVersion Length]" + getInfo.length());
dModVersionList.addElement(getInfo);
}
} catch (Exception e) {
dModVersionList.addElement("Unknown");
e.printStackTrace();
}
}
即使while循环返回null,我也想添加元素,如果页面不再存在,我已经可以处理它