java - Folder are file not zipping -
i have implemented zip folder or file download , saving memory. problem is, downloading without error not getting zip file, , if click on downloaded file showing:
can't show
or
can't display message.
my code:
string filename = tvtitle.gettext().tostring(); string fileextension = tvtype.gettext().tostring(); file imagedirectory = new file(path); imagedirectory.mkdirs(); int filelength = connection.getcontentlength(); string _path = path; input = connection.getinputstream(); file outputfile = new file(_path, filename + fileextension); fileoutputstream fos = new fileoutputstream(outputfile); zipoutputstream zos = new zipoutputstream(fos); file srcfile = new file(input.tostring()); byte[] buffer = new byte[1024]; zos.putnextentry(new zipentry(srcfile.getname())); int length; while ((length = input.read(buffer)) > 0) { zos.write(buffer, 0, length); } zos.closeentry(); input.close(); zos.close();
i don't know type of variable "input"
i think should have fileinputstream (reading source file) paired fileoutputstream (set destination/zip file).
and line of code:
file outputfile = new file(_path, filename + fileextension);
your output must .zip file right? so, should be:
file outputfile = new file(_path, filename + ".zip");
or similar
and this
string filename = tvtitle.gettext().tostring(); string fileextension = tvtype.gettext().tostring(); file imagedirectory = new file(path); fileinputstream fis = new fileinputstream(imagedirectory); zipentry zipentry = new zipentry(filename); fileoutputstream fos = new fileoutputstream("test.zip"); zipoutputstream zos = new zipoutputstream(fos); zos.putnextentry(zipentry); byte[] bytes = new byte[1024]; int length; while ((length = fis.read(bytes)) >= 0) { zos.write(bytes, 0, length); } zos.closeentry(); fis.close(); zos.close(); fos.close();
Comments
Post a Comment