嗯,我不确定试试这个,看看是否有任何更改或错误。我还认为也许您将 setRedirects(boolean b) 设置为 false 这也可能会出现问题,但请先尝试以下操作:
URLConnection con = null;
InputStream in = null;
try {
String webadd="urls go here try the two you have had probelms with and success";
URL url = new URL(webadd);
con = url.openConnection();
con.setConnectTimeout(10000);
con.setReadTimeout(10000);
in = con.getInputStream();
Image img = ImageIO.read(in);
if (img != null) {
System.out.println("Loaded");
} else {
System.out.println("Could not load");
}
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if(is != null) {
try {
is.close();
} catch(IOException ex) {
// handle close failure
}
}
if(con != null) {
con.disconnect();
}
}
}
编辑:或者可能是一个错误?: http://bugs.sun.com/view_bug.do;jsessionid=2bc7386e2f8b4e2550f8b10122f?bug_id= 6309072检查是否仍然出现上述代码尝试:
Image img=new ImageIcon(url).getImage();