Java 下载带有HttpURLConnection问题的*.deb文件

Java 下载带有HttpURLConnection问题的*.deb文件,java,ubuntu,Java,Ubuntu,我尝试使用HttpURLConnection实现下载功能,但当文件后缀为“.deb”时,例如file1.deb、file2.deb,则下载文件不完整 为什么? 这是我的密码 DownloadInfo downloadFile(String source, String saveDirectory)throws HTTPException { URL url = new URL(source); HttpURLConnection connection = (HttpURLCo

我尝试使用HttpURLConnection实现下载功能,但当文件后缀为“.deb”时,例如file1.deb、file2.deb,则下载文件不完整

为什么?

这是我的密码

DownloadInfo downloadFile(String source, String saveDirectory)throws HTTPException {

    URL url = new URL(source);

    HttpURLConnection connection = (HttpURLConnection) url.openConnection();

    int responseCode = connection.getResponseCode();

    if (responseCode != HttpURLConnection.HTTP_OK) {
        throw new HTTPException(responseCode);
    }

    String httpContent = getResponseHeadContent(connection);

    Path saveFilePath = produceSavePath(source, saveDirectory);
    Files.copy(connection.getInputStream(), saveFilePath, StandardCopyOption.REPLACE_EXISTING);

    connection.disconnect();

    DownloadInfo info = new DownloadInfo();
    info.setFilePath(saveFilePath);
    info.setHttpHeadContent(httpContent);

    return info;
}

我得到的原因,因为链接服务器是IIS。IIS不提供未知文件类型,则“.deb”不在MIME类型中。我必须手动添加它

@mpromonet谢谢你的回答,但我的意思是文件后缀是“.deb”,然后下载成功,但文件不完整。