V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
caihp
V2EX  ›  Java

使用 HttpURLConnection 下载文件只能下载到 1G

  •  
  •   caihp · 117 天前 · 1063 次点击
    这是一个创建于 117 天前的主题,其中的信息可能已经有所发展或是发生改变。
    现在有个需求是通过后台下载文件,下载大于 1G 的文件的时候下到 1G 就会报 SocketException:Connection reset 或者 SocketException:Time out, 请问这个应该是哪里的大小限制住了
    下载的代码如下:
    HttpURLConnection httpConn = null;
    URL url = new URL(Splitter.on("?").splitToList(file.getFileUrl()).get(0));
    httpConn = (HttpURLConnection) url.openConnection();
    httpConn.connect();
    InputStream is = httpConn.getInputStream();
    zos.putNextEntry(new ZipEntry(folderName + "/" + file.getName()));
    int length;
    while ((length = is.read(buffer)) > 0) {
    zos.write(buffer, 0, length);
    }
    is.close();
    3 条回复    2024-01-02 17:02:59 +08:00
    tanranran
        2
    tanranran  
       117 天前
    和 HttpURLConnection 无关,应该是后端有限制,检查下后端网关的配置
    caihp
        3
    caihp  
    OP
       117 天前
    @salmon5

    @tanranran
    谢谢老哥,解决了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3239 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 11:52 · PVG 19:52 · LAX 04:52 · JFK 07:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.