how can I convert a zip file into bytes?
byte[] ba; InputStream is = new ByteArrayInputStream(ba); InputStream zis = new ZipInputStream(is);
You can read a file from disk into a byte[] using 
 byte[] ba = java.nio.file.Files.readAllBytes(filePath);
This is available from Java 7.
The basic principle is to feed the InputStream into the OutputStream, for example...
byte bytes[] = null;
try (FileInputStream fis = new FileInputStream(new File("..."))) {
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        byte[] buffer = new byte[1024];
        int read = -1;
        while ((read = fis.read(buffer)) != -1) {
            baos.write(buffer, 0, read);
        }
        bytes = baos.toByteArray();
    } 
} catch (IOException exp) {
    exp.printStackTrace();
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With