这是我用来下载图像并保存的代码。任何人都可以建议我还需要做什么或我在这里错过了什么吗?提前致谢
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
BufferedWriter writer = null;
InputStream in = new BufferedInputStream(request.getInputStream());
try {
byte[] buffer = new byte[100000];
int n = -1;
while ((n = in.read(buffer)) >= 0) {
out.write(buffer, 0, n); // used for image
}
out.close();
byte[] res = out.toByteArray();
out.flush();
FileOutputStream fos = new FileOutputStream("D://"+ new SimpleDateFormat("yyyyMMdd_HHmmssss").format(Calendar.getInstance().getTime()) +".jpg");
fos.write(res);
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}