Here: // Add ZIP entry to output stream. Out. PutNextEntry(new ZipEntry(filename)); You're creating the entry for that file using the whole path.
If you just use the name ( without the path ) you'll have what you need: // Add ZIP entry to output stream. File file = new File(filename); //"Users/you/image. Jpg" out.
PutNextEntry(new ZipEntry(file.getName())); //"image.jpg.
You're finding your source data using the relative path to the file, then setting the Entry to the same thing. Instead you should turn the source into a File object, and then use putNextEntry(new ZipEntry(sourceFile.getName())) that'll give you just the final part of the path (ie, the actual file name).
Thanks! It works great – Ignacio Jun 11 '10 at 3:33.
Do as Jason said, or if you want to keep your method signature, do it like this: out. PutNextEntry(new ZipEntry(new File(filename).getName())); or, using FileNameUtils. GetName from apache commons/io: out.
PutNextEntry(new ZipEntry(FileNameUtils. GetName(filename))).
You could probably get away with accessing source files via new FileInputStream(new File(sourceFilePath, sourceFileName)).
Easy way of zip a file import java.io. *; import java.util.zip. *; public class ZipCreateExample{ public static void main(String args) throws Exception { // input file FileInputStream in = new FileInputStream("F:/ZipCreateExample.
Txt");; // out put file ZipOutputStream out =new ZipOutputStream(new FileOutputStrea("F:/tmp. Zip")); // name of file in zip folder out. PutNextEntry(new ZipEntry("zippedfile.
Txt")); byte be = new byte1024; int count; // writing files to new zippedtxt file while ((count = in. Read(b)) > 0) { System.out.println(); out. Write(b, 0, count); } out.close(); in.close(); } }.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.