|
-
May 15th, 2012, 02:32 PM
#1
putting non local files into a zip
Code:
byte[] buf = new byte[1024];//time to make zip file
String zipName="name.zip";
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipName));
for(int i=0; i<copy.length; i++){//put all pdfs in the zip
FileInputStream zipFile = new FileInputStream(copy[i]);
out.putNextEntry(new ZipEntry(copy[i]));
int len;
while((len=zipFile.read(buf))>0){
out.write(buf, 0, len);
}
out.closeEntry();
zipFile.close();
}
out.close();
copy is an array of strings which contain the file path for each file I want (for example C:\files\test.pdf, I have tested it yes the correct values are in it). It compiles and runs fine with no exceptions and creates the zip folder, but nothing is in said zip folder.
Note, I also have an array of files (which I used to fill copy using toString) if that would be easier. ZipEntry only seems to accept strings which is why I tried to do it this way.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|