Download compressed folder (.zip) from a URL (FTP) with JAVA

Asked

Viewed 67 times

0

I am trying to download a "zipped" folder through the URL http://portal.insoft4.com.br/site/Download/RepositorioSCR/Teste.zip (FTP) with the following code snippet made in Java:

try (BufferedInputStream in = new BufferedInputStream(new URL(DOWNLOAD_PATH + fileName + ".zip").openStream());
             FileOutputStream fileOutputStream = new FileOutputStream(SAVE_PATH + fileName + ".zip")) {
//            byte[] dataBuffer = new byte[1024];
            int bytesRead;
            while ((bytesRead = in.read()) != -1) {
                fileOutputStream.write(bytesRead);
            }

        } catch (IOException e) {
            StringWriter sw = new StringWriter();
            e.printStackTrace(new PrintWriter(sw));
            String exceptionDetails = sw.toString();

            log.error(exceptionDetails);
            updateStatusToError();
        } 

But when trying to extract the downloaded file, the following error is reported:

Arquivo desconhecido

Objeto movido

Can anyone explain why the file is corrupted and of different size?

What would be the correct way to download a folder compressed with other files (photos, files .jar and .ini) within?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.