public static void main(String[] args) throws IOException {
URL url = new URL(
"http://img.verycd.com/vcgroup/gface/48-48/143661.jpg");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(10 * 1000);
conn.setRequestMethod("GET");
int code = conn.getResponseCode();
System.out.println(code);
File file = new File("9.jpg");
file.createNewFile();
InputStream is = new BufferedInputStream(conn.getInputStream());
OutputStream os = new BufferedOutputStream(new FileOutputStream(file,
true));
byte[] buf = new byte[1024];
int len = 0;
while ((len = (is.read(buf))) != -1) {
os.write(buf, 0, len);
}
os.flush();
os.close();
is.close();
}