I am reading a large zip file but my code giving me negative array size exception
// Simplest read of an entire file into a byte array
// Will throw exceptions for file not found etc.
private static byte[] loadFileAsByteArray(String path) throws IOException {
File file = new File(path);
InputStream is = new FileInputStream(file);
byte[] data = new byte[(int) file. Length()];
is.read(data);
return data;
}
Please tell me how I can read a long zip file data in bytes
file.length()can legitimately return 0 (if you have the wrong file or a special file) and it's undefined what happens if you gave a "path" rather than file to that call.ZipFileandZipEntrythat handle zip files better? Take a look at tutorials.jenkov.com/java-zip/zipfile.htmlversionfield? And how is an entirezipfile a version?