java batch packs multiple files into zip format

public void createzip(){
		List<File> nFileList = new ArrayList<File>();
		nFileList.add(new File("C:\\Users\\Administrator\\Desktop\\test move to \\0001+Guidance by the General Office of the State Council on Actively Promoting Supply Chain Innovation and Application.doc"));
		nFileList.add(new File("C:\\Users\\Administrator\\Desktop\\test moved to \\0001+Guidelines of the General Office of the State Council on Actively Promoting Supply Chain Innovation and Application.pdf"));
		nFileList.add(new File("C:\\Users\\Administrator\\Desktop\\zenith.product.fms.main.js"));
		String strZipName = "C:\\Users\\Administrator\\Desktop\\lx.zip";
		FileInputStream nFileInputStream = null;
		ZipOutputStream nZipOutputStream = null;
		try {
			nZipOutputStream = new ZipOutputStream(new FileOutputStream(strZipName));
			for (File file : nFileList) {
				nFileInputStream = new FileInputStream(file);
				nZipOutputStream.putNextEntry(new ZipEntry(file.getName()));
				int len;
				while ((len = nFileInputStream.read()) != -1) {
					nZipOutputStream.write(len);
					nZipOutputStream.flush();
				}
			}
			nZipOutputStream.close();
			nFileInputStream.close();
			System.out.println("Generation of lx.zip succeeded");   
		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace ();
		}
	}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326119278&siteId=291194637