find zip file length lessthen 5MB

find zip file length lessthen 5MB

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class Zipingfile {
    BufferedReader readkeyboard=new BufferedReader(new InputStreamReader(System.in));
    public static int buffer = 5242890;
    String source,detination;
    long overallSize = 0;
    public void zipingfile() { 
        try {
            System.out.println("Enter source path :");
            source=readkeyboard.readLine();                     
            //creating ziping
            File folder = new File(source);
            if(folder.exists()) {        
                System.out.println("Enter Destination path :");
                detination=readkeyboard.readLine();

            File[] files = folder.listFiles();
            File zipedfile=new File(detination);
            byte binarybits[] = new byte[buffer];
            FileOutputStream writefile = new FileOutputStream(zipedfile);
            ZipOutputStream zip = new ZipOutputStream(writefile);

            for (int i = 0; i < files.length; i++) {                
                //if (files[i] == null || !files[i].exists()|| files[i].isDirectory())  
                //System.out.println();
                ZipEntry addFiles = new ZipEntry(files[i].getName());
                addFiles.setTime(files[i].lastModified());
                overallSize+=zipedfile.length();
                //if(files[i].length() >= buffer) {
                //continue;
                //}
                zip.putNextEntry(addFiles);
                if(overallSize < buffer) { 
                //zip.putNextEntry(new ZipEntry(files[i].getName()));

                FileInputStream readfile = new FileInputStream(files[i]);
                while (true) {
                    System.out.println("infiniti loopppp");
                  int filelen = readfile.read(binarybits, 0, binarybits.length);
                 // System.out.println(">>>>>>>>"+filelen);
                  //if file is empty or >5mb
                  if (filelen <= 0)                   
                      break;
                  zip.write(binarybits, 0, filelen);
                  }
                readfile.close();
                }
                 else{
                        System.out.println("zip file morethan 5MB zip is not possible");
                        //zip=null;
                        /*for (File file : files)
                            {
                            // Delete each file

                            if (!file.delete())
                            {
                            // Failed to delete file

                            System.out.println("Failed to delete "+file);
                            }
                            } */
                    //  zip.delete();
                        return;
                    }
            }           
              System.out.println("Zip File is created successfully.");
              System.out.println("File Name: " + zipedfile.getName());
              System.out.println("Destination path : " + zipedfile.getPath());
              //int size= zipedfile.length()*1024*1024;
              System.out.println("File size: " + zipedfile.length() + "bytes ");
              zip.close();
              writefile.close();


            }else {
                System.out.println("file doesn't exist");
            }
        } catch(IOException io){
            io.printStackTrace();
        }       
    }
public static void main(String[] args) {        
        Zipingfile filezip=new Zipingfile();
        filezip.zipingfile();
    }
}
View Answers









Related Tutorials/Questions & Answers:
find zip file length lessthen 5MB
find zip file length lessthen 5MB  import java.io.BufferedReader...(); } else{ System.out.println("zip file morethan 5MB zip is not possible"); //zip=null
sending a zip file to servlet
sending a zip file to servlet  I have created a .zip file in a servlet on the local system(no static ip). The .zip file contains xml files. I have to send it to another servlet which is in a server(has a static ip). I have done
Advertisements
convert a file .doc to .zip
convert a file .doc to .zip  hiii, I uploaded a file with extension .doc now i required with .zip   Hi Friend, Try the following code...;TITLE>Display file upload form to the user</TITLE></HEAD> <
Create a new zip file in ZipArchive.
Creating a new Zip file in ZipArchive For creating zip file, use zipArchive () class. Create a new zip file in ZipArchive. Use the conditional statement... will generate a new zip file, in case of failure, it will print failed in creating
How to zip a file using javascrip?
How to zip a file using javascrip?  hi.. can anyone tell me How to zip a file using javascrip
convert zip file to byte array
convert zip file to byte array  Hi,How to convert zip file to byte array,can you please provide program?? Thanks, Ramanuja
Java file zip
Java file zip In this section, you will learn how to create a zip file. The ZIP file format is used for the distribution and storage of files. It is a compressed format file which takes less space then the original file. The zip file
zip file upload in php - WebSevices
zip file upload in php  This is not a normal upload. we know the code for normal upload. i need the zip file upload code in php. how to upload zipfile using php? and how to unzip using php? please i dont
Read file zip in J2ME - MobileApplications
Read file zip in J2ME  I would like to read file.zip in J2ME,I don't know how to extract it. Please help me
Issue in Converting .zip file to .jar file?
Issue in Converting .zip file to .jar file?  I have a folder called "printpdf.jar". I have changed the .jar to .zip and did some customizations. After which i had "zipped" it again and made as ".jar". Now the final file
Unzip a ZIP File
Unzip a ZIP File       How to unzip (extract) a zip file? How to retrieve elements from a zip format file? All these type of questions are solved through
How to extract zip file in java.
How to extract zip file in java. In this Example, we will discuss how to extract a ZIP file. We will use ZipInputStream class for creating input stream that take input from ZIP file. The ZipInputStream class is available
Where to download spring framework zip file?
Where to download spring framework zip file?  Hi, I am trying to find the link to download the full distribution zip file of the Spring Framework.... Can anyone tell me the url from where I can download the full zip file
Creating a ZIP file in Java
Creating a ZIP file in Java       Zip File: Zip file format is the popular method of data compression. Zip file contains many files in compressed format. You can
Create zip file in Java
Create zip file in Java       Introduction In this section, you will know about a zip file. You will also learn how to create a zip file from any file through the java
How to create a zip file and how to compare zip size with normal text file
How to create a zip file and how to compare zip size with normal text file .../ZipCreateExample.shtml but when i verified the size of zip and normal file,normal file is showing as 12 bytes and zip file was showing 150bytes in Dos prompt.Is there any error
Read a zip file.
in reading a zip file. First select a file to be opened. Name that file into zip file and direct the zipread command to read it through while loop. The zip_entry..., it will executed and file will be closed.  <?php $zipname = zip_open("
Listing Contents of a ZIP File
Listing Contents of a ZIP File     ... of a zip file through the java code. Following program helps you for the appropriate... list of elements present in the zip file format. Program Result:ADS_TO_REPLACE_1
Zip File Using Java
; This example shows how to create a zip file in java. In other words, we... applications. This example shows how we zip a file through a java program... to write files in the zip file format. This class can be used for both compressed
Show all the entries of zip file.
Show all the entries of zip file. In this tutorial, We will  discuss how to show all the entries of a zip file.  The ZipFile   class is used...; returns enumeration of zip file entries. The getName() method
How to make a zip file in java
Description: In this example we will discuss about how to create zip file from the text file. In the following code  ZipOutputStream class from... zip file. Code: import java.io.*; import java.util.zip.
How to extract a zip file to a folder in Linux?
How to extract a zip file to a folder in Linux? Step by step command... content of a zip file to a specified directory. If you have a zip file and you... use this command to extract a zip file. This tutorial will explain you how
How to generate hash code of Zip file.
How to generate hash code of Zip file. In this tutorial, we will see how to generate hash code of zip file entries. The ZipFile   class is used to read...;returns enumeration of zip file entries. The hashCode() method of ZipFile
password protected zip file creation exmpale coded neaded - JSP-Servlet
password protected zip file creation exmpale coded neaded  am able to create a zip file and able to read the file but password protection need please help
Retriving zip file stored in database into my own filesystem
Retriving zip file stored in database into my own filesystem  Hi all... several zip file stored in this table now I want to retrieve it and put it in an directory in my file system. PreparedStatement psmt=con.prepareStatement("select
How to upload zip file from android to server programmatically?????
How to upload zip file from android to server programmatically?????  hi , I want to upload zip file from android phone sdcard to server programmatically. So any one do this task in past so please share your experience with me
To find palindrome no in a file - Java Beginners
To find palindrome no in a file  hi all i am having a problem...I wanted to write one java program where i have to count the no of palindrome in a file. I tried it with my own but not able to get result.pls help me out  
Mysql Length Function
Mysql Length Function       The Tutorial already illustrate you an example to find the length of the String. Now this section of tutorial helps you to find the Length
Mysql Length Function
Mysql Length Function       The Tutorial already illustrate you an example to find the length of the String. Now this section of tutorial helps you to find the Length Function
How to find a config file in spring project
How to find a config file in spring project  how to find configuration file in the spring project
how to find which user has modified the file
how to find which user has modified the file  how to find which user has modified the file
Find the percentage of words which starts with a vowel in a file
Find the percentage of words which starts with a vowel in a file   Question: Find the percentage of words which starts with a vowel in a file. Ex: Input: Contents of File1- There is an endless loop in the program. Output: Vowel
Program to find no of metrics in a file ----- Java code
Program to find no of metrics in a file ----- Java code  Hi Friends, I got a task to calculate the metrics of a program, like to find... the no of SELECT and INSERT statements but unable to find tablewise. E.G Table
PHP Array Length
Here you will learn how you find the PHP Array Length. You can find the Array Length using the sizeof() and count() functions. As you know, PHP... about the Array length and the two different ways to get the size of array. Array
tO FIND UNIQUE WORDS IN A FILE USING HASHMAP
tO FIND UNIQUE WORDS IN A FILE USING HASHMAP  import java.util.*; import java.io.*; public class countunique { private String[] splitter...())); } System.out.println("Number of unique words in file "+cc
Find the date of the file before the file has been modified
Find the date of the file before the file has been modified  Hi, may i know is it possible to find the date of the file before the file has been modified?   hi friend, you can get the date of last modified file using
Error 500-Server are not find the jar file in the program of upload the file - JSP-Servlet
Error 500-Server are not find the jar file in the program of upload... a program to upload a file.I include the commons-fileupload-1.2.1.jar file in lib...); // Create a new file upload handler System.out.println(isMultipart); DiskFileUpload
Create zip file in Java
Zip Code
Zip Code   I have 4 excel file and i want to zip that files also i need password protect when i open that file please write that code for local machine also write in using javascript
length in array
length in array  wat s length in array
Java Zip Package
and writing the standard and compressed files or archives in the ZIP and GZIP file formats. Basically, ZIP file forms for the JAR file format, so it is easier... entries in a ZIP file. A ZipFile object can be created with a File object
length in array
length in array  hi wat is length in array and where s it used
Need to find the position of delimiter in a file using java - Java Beginners
Need to find the position of delimiter in a file using java  Hi , will any one give me a solution to find the Need to find the position of delimiters in a file using java.Please do reply
length in array
length in array  hai wat s length in array and where it s used
find jar file name from multiple set of jar files
find jar file name from multiple set of jar files   I would like to find jar file name from multiple set of jar files where the given class nameââ?¬Â?com.rational.ft.util.debugââ?¬Â
Java - search/find a word in a text file - Java Beginners
Java - search/find a word in a text file  Hello, I would like to know how to find from a list of lets say 10 but could be more, .txt files, how... want to do nothing, if FAIL, I want to record in 1 master output file, the name
length of etag
length of etag  etag header in http - Does the HTTP protocol specify a max length for the ETag?   No, HTTP protocol do not specify a max length for the ETag
String length property example
that we have apply length property to find out the length of the string. Output... .style1 { font-size: medium; } String Length property example in Action Script3:- If user want to find out number of characters in a string
schedule zip
schedule zip  Java Code to automatically get and zip only .txt files from folders for every 5 days and also to send the zip files to database tables
php array length sizeof
php array length sizeof  php array length sizeof function

Ads