over 9 years ago
Here I am writing code to create zip file in android application.
Here, First I create directory where I create zip file.
Then by using Compress class I create zip file having some valid images already saved on our device.
- private File createZipFile() {
- ZIP_FILE_NAME = getDateName() +".zip";
File directory = new File(Environment.getExternalStorageDirectory(),getString(R.string.app_name));
- if(!directory.exists())
- {
- directory.mkdir();
- }
- File f = new File(directory, ZIP_FILE_NAME);
- return f;
- }
- public String getDateName() {
- Date date = new Date();
- String format = "yyMMddHHmm";
- SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.US);
- String dateString = sdf.format(date);
- String fileName = "Example" + dateString;
- return fileName;
- }
- final String zipFile=createZipFile().getAbsolutePath();
- String fileName[] = new String[]{};
- fileName=new String[]{image1,image2,image3,image4};
- Compress compress=new Compress(fileName, zipFile);
private File createZipFile() { ZIP_FILE_NAME = getDateName() +".zip";File directory = new File(Environment.getExternalStorageDirectory(),getString(R.string.app_name)); if(!directory.exists()) { directory.mkdir(); } File f = new File(directory, ZIP_FILE_NAME); return f; } public String getDateName() { Date date = new Date(); String format = "yyMMddHHmm"; SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.US); String dateString = sdf.format(date); String fileName = "Example" + dateString; return fileName; } final String zipFile=createZipFile().getAbsolutePath(); String fileName[] = new String[]{}; fileName=new String[]{image1,image2,image3,image4}; Compress compress=new Compress(fileName, zipFile);
0 Comment(s)