If you need to reprint, please indicate the source and the author. Thank you QQ: 221704msn: flyly@yeah.netemail: zhangfl@sports.cn
Today, use java.util.zip to make file compression. After writing the program, I found that the compressed package brought into all path directories of the original file.
/ ** * Generate zip file * Return to zip file address * @Param imgids string [] * @Return string * / public string createzip (string [] imgids) {string [] filenames = getPath (IMGIDS); // According to image ID return path Date date = new Date (); byte [] buf = new byte [1024]; String outFilename = zippath String.valueOf (date.getTime ()) ". zip"; try {ZipOutputStream out = new ZipOutputStream ( new FileOutputStream (outFilename)); for (int i = 0; i
In fact, the problem appears in zipentry zipentity = new zipentry (filenames [i]); I discovered this file name with full path after I Println this filename [i].
Solution
Public string createzip (string [] imgids) {string [] filenames = getPath (imgids); Date Date = new Date (); byte [] buf = new byte [1024]; string outfileename = zippath string.valueof (date. getTime ()) ". zip"; try {ZipOutputStream out = new ZipOutputStream (new FileOutputStream (outFilename)); for (int i = 0; i