url连接可以在浏览器直接看到图片但是通过后台代码保存到本地的图片显示图片错误
神歌圣音 2020-03-30 04:16:22 url连接可以在浏览器直接看到图片但是通过后台代码保存到本地的图片显示图片错误
这是后台代码
URL url = null;
try {
Authenticator.setDefault(new MyAuthenticator("admin","123456"));
//HttpClientUtil.getHttpClient();
url = new URL(urlList);
DataInputStream dataInputStream = new DataInputStream(url.openStream());
FileOutputStream fileOutputStream = new FileOutputStream(new File(savePath));
ByteArrayOutputStream output = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = dataInputStream.read(buffer)) > 0) {
output.write(buffer, 0, length);
}
byte[] context=output.toByteArray();
fileOutputStream.write(output.toByteArray());
dataInputStream.close();
fileOutputStream.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}