有没有办法通过 httpurl 连接下载 .jar 文件?

Is there a way to download a .jar file with a httpurlconnection?

服务器正在发送一个 jar 文件,我想将它保存在一个特定的目录中。 我的 HttpURLConnection 只读取文件的内容

public static String update(String url, String version) throws MalformedURLException, IOException {
    HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection();
        
    return readResponse(con.getInputStream());
}
private static String readResponse(InputStream in){
    BufferedReader br = new BufferedReader(new InputStreamReader((in)));
    StringBuilder sb = new StringBuilder();
    String output;
    while ((output = br.readLine()) != null) {
        sb.append(output);
    }
    return sb.toString();
}

为什么要将它作为字符串传递? 也许试试 (https://www.baeldung.com/java-download-file)

InputStream in = new URL(FILE_URL).openStream();
Files.copy(in, Paths.get(FILE_NAME), StandardCopyOption.REPLACE_EXISTING);