gpt4 book ai didi

java - 图片正在部分下载,

转载 作者:塔克拉玛干 更新时间:2023-11-01 19:07:26 24 4
gpt4 key购买 nike

我无法下载以下网址中的文件:http://avisloyalty.eu/assets/fleetlarge//VW_Passat_15.jpg

只下载了文件的一部分。

以下是我的代码。如果我做错了什么,请告诉我。

URLConnection urlConn = new URL( "http://avisloyalty.eu/assets/fleetlarge//VW_Passat_15.jpg").openConnection();
InputStream is = urlConn.getInputStream();
FileOutputStream fos = new FileOutputStream( file.getPath() );

byte[] buffer = new byte[4096];
int len;

while( ( len = is.read( buffer ) ) > 0 )
{
fos.write( buffer, 0, len );
}
fos.close();

最佳答案

我刚试过这个...

    HttpClient client = HttpClientBuilder.create().build();
HttpGet get = new HttpGet("http://avisloyalty.eu/assets/fleetlarge//VW_Passat_15.jpg");

HttpResponse execution = client.execute(get);
HttpEntity entity = execution.getEntity();
FileOutputStream outputStream = new FileOutputStream("C:\\tmp\\imgout.jpg");

if (entity != null) {
InputStream inputStream = entity.getContent();
IOUtils.copy(inputStream, outputStream);
}

outputStream.close();

...并且输出文件包含 TEXT...

<HTML>
<HEAD>
<TITLE>avisloyalty.eu</TITLE>
<META NAME="robots" CONTENT="noindex">
</HEAD>
<FRAMESET FRAMESPACING="0" BORDER="0" FRAMEBORDER=No ROWS="100%,*">
<FRAME SRC="https://www.avisloyalty.eu/assets/fleetlarge//VW_Passat_15.jpg">
</FRAMESET>
<NOFRAMES>
Sorry, your browser doesn't seem to support frames! <br>
Proceed to <A href="https://www.avisloyalty.eu/assets/fleetlarge//VW_Passat_15.jpg">https://www.avisloyalty.eu/assets/fleetlarge//VW_Passat_15.jpg</A> manually.
</NOFRAMES>
</HTML>

所以您的代码可能没有问题(不过我仍然会使用 != -1 而不是 > 0)!也许你需要设置一个请求头或其他东西......

关于java - 图片正在部分下载,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29350380/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com