KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I've successfully modified the contents of a (existing) zip file using the FileSystem provided by java 7, but when I tried to create a NEW zip file by this method it fails, with the error message that says: "zip END header not found" , it is logical because of the way I'm doing it, first I create the file ( Files.createFile ) which is a completely empty file, and then I try to access to its file system , and since the file is empty its impossible to find any header inside the zip, my question is is there any way to create a new zip file completely empty using this method?; the hack that I've considered is adding an empty new ZipEntry to a the zip file and then using that new empty file to crate the file system based on it, but i really want to think that the guys of oracle implemented a better (easier) way to do this with nio and the filesystems... this is my code (the error appears when creating the file system): if (!zipLocation.toFile().exists()) { if (creatingFile) { Files.createFile(zipLocation); }else { return false; } } else if (zipLocation.toFile().exists() && !replacing) { return false; } final FileSystem fs = FileSystems.newFileSystem(zipLocation, null); . . . zipLocation is a Path creatingFile is a boolean ANSWER: in my particular case the answer given didn't work appropriately because of the spaces in the path, therefore i have to do it the way i didn't want to: Files.createFile(zipLocation); ZipOutputStream out = new ZipOutputStream( new FileOutputStream(zipLocation.toFile())); out.putNextEntry(new ZipEntry("")); out.closeEntry(); out.close(); it does not mean that the given answer is wrong, it just didn't work for my particular case
Tags (comma-separated)
Save Edits
Cancel