Home Tutorialhelp Comment ZipFolder using java by format date

 
 

Comment

Hien
ZipFolder using java by format date,
December 3, 2009 at 8:22 AM

package com.smedia.filetranfer;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

/**
* Created by IntelliJ IDEA.
* User: The Hien
* Date: Sep 22, 2009
* Time: 2:50:10 PM
*/
public class ZipFolder {
public static void main(String arg[]) throws Exception {
int dayBefore = 1;

String srcFolder = "C:\\Documents and Settings\\The Hien\\Desktop\\LogXS";


Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_YEAR, -dayBefore);
// SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyy");

/*Tim thu muc ngay hom truoc se la: 102009/18102009*/

DateFormat dateFormat = new SimpleDateFormat("/MMyyyy/ddMMyyyy");
srcFolder = srcFolder + dateFormat.format(calendar.getTime());

String destZipFile = srcFolder + ".zip";

File file = new File(srcFolder);
if (file.exists() && file.isDirectory()) ;

zipFolder(srcFolder, destZipFile);
(new SendFile()).fileTranfer();
DelFolder.deleteDir(new File(srcFolder));

/* Nen folder 6/9/2009-> Path folder: 092009/06092009
Kiem tra folder ton tai , neu ton tai thi zip thu muc 06092009-> 06092009.zip
Gui len ftp server vao thu muc [desdir]/092009/
*/
}

static public void zipFolder(String srcFolder, String destZipFile) throws Exception {
ZipOutputStream zip = null;
FileOutputStream fileWriter = null;
boolean ziped = false;
try {
fileWriter = new FileOutputStream(destZipFile);
zip = new ZipOutputStream(fileWriter);

addFolderToZip("", srcFolder, zip);
ziped = true;
System.out.println("Your file " + (ziped ? "" : "not ") + "zipped .");
}

finally {
if (null != zip) zip.close();
if (null != fileWriter) fileWriter.close();

}
}

static private void addFileToZip(String Path, String scrFile, ZipOutputStream zip) throws Exception {

File folder = new File(scrFile);
if ((folder.isDirectory())) {
addFolderToZip(Path, scrFile, zip);
} else {

byte[] buffer = new byte[1024];
int len;
FileInputStream in = null;
try {
in = new FileInputStream(scrFile);
zip.putNextEntry(new ZipEntry(Path + "/" + folder.getName()));

/* putNextEntry(new ZipEntry(filesToZip)) là m?t ph??ng th?c c?a l?p ZipOutputStream
dùng ?? ??a vào t?ng file m?t ?? nén l?i.*/

while ((len = in.read(buffer)) > 0) {
zip.write(buffer, 0, len);
}
}
finally {
if (null != in) in.close();
}
}
}

static private boolean addFolderToZip(String subFolder, String srcFolder, ZipOutputStream zip)
throws Exception {

File folder = new File(srcFolder);
try {
for (File item : folder.listFiles()) {
if (item.isDirectory()) addFolderToZip(subFolder + "/" + item.getName(), item.getPath(), zip);
else {
addFileToZip(subFolder, item.getPath(), zip);
}
}

return true;
} catch (Exception e) {
e.printStackTrace();

}
return false;
}
}

View All Comments | View Tutorial
Advertisement
Related Tutorial and Articles
Struts 2 Tutorials

struts2.2.1 date Format example
struts2.2.1 date Format example. In this example, We will discuss about the different type of date format using struts2.2.1. Directory structure of example... Format Example</title> </head> <body> <h2>Date 

Java Beginners

Import java IO - Java Beginners
Import java IO  for example i know java IO is for input and output. I am using Netbeans5.5.1. How can i see all the classes related to java IO for example; stream reader, buffer reader 

Java Beginners

java io
java io  by using java coding how to invoke a particular directory 

Java Technology Tutorials

Formatting a Date Using a Custom Format
Formatting a Date Using a Custom Format In this section, you will learn how to format a date using a custom format. Java has provide many classes that allow a programmer to format the date and time. Here we have used SimpleDateFormat 

Java Beginners

java binary file io example
java binary file io example  java binary file io example 

Java Beginners

io
io  create a meanu based text editor in java having features of creating file,viewing file,deleting file,renaming file,copying file and cutting file 

Java Beginners

io
io  write a program in java to accept a filename from user and print its content on the monitor   Hello Friend, Try the following code: import java.io.*; import java.util.*; class DisplayContentOfFile { public 

Java Beginners

java io
java io  Write a program to use a File object and print even numbers from two to ten. Then using RandomAccessFile write numbers from 1 to 5. Then using seek () print only the last 3 digits 

Date Calendar

Date format - Date Calendar
field.Every time i need to check the format of the date field and make sure the correct format and then display it. How can i format it using java and also can we do...Date format  Hi All, I am getting a date from database as a format 

Java Technology Tutorials

Parsing a Date Using a Custom Format
Parsing a Date Using a Custom Format In this section, you will learn how to parse a date using a custom format. Java has provide many classes for handling... to parse the date in different language. In the given example, we have 

Java Beginners

io packages - Java Beginners
io packages  How can I add two integers in java using io pacages 

Java-Tutorials

Java Date Format Example
Java Date Format Example You can format date in many ways. In this tutorial Format class is used to format the java date in to the different formats... = dateFormat.format(date); You can format the date into specific locale. For example 

Programming Tutorials

File IO
are planning to learn file management using Java IO package.This class is available... The Java IO package is used to perform various input/output processing activities.In this section we are giving overview of java IOJava io classes 

Java Beginners

String to date with no format
into a date .. this is simple .. but i want to do it without knowing the date format.... but i want to write a java program to find out dis format for me. the result... date format can be (mm-dd-yyyy) if the 99th record also was 06-06-2006 

Java Beginners

java-io - Java Beginners
java-io  Hi Deepak; down core java io using class in myn...://www.roseindia.net/java/java-conversion/two-dimensional-array-program-using-nested-loop.shtml http://www.roseindia.net/java/beginners/SquareMatrix.shtml Thanks 

Java-Tutorials

Java IO Path
Java IO Path In this section we will discuss about the Java IO Path. Storage... is called a Path of that file or folder using which they can be accessed easily.... These sub folders can contains a file or sub folders and so on. For example 

Java Beginners

java format date
java format date  Hi, How can I format the date in the following...) { Date date=new Date(); SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); String formattedDate=sdf.format(date 

Java Interview Questions

String to Date format
String to Date format  My Date format is String Eg(Jan 20 2011 ).... How to Change This values Like to database date format Eg(2011-01-20) using java   import java.util.*; import java.text.*; class ChangeDateFormat 

Programming Tutorials

Working With File,Java Input,Java Input Output,Java Inputstream,Java io Tutorial,Java io package,Java io example
to work with a file using the non-stream file I/O. The File class is used... files using the File class. This class is available in the java.lang package...; Lets see an example that checks the existence of  a specified file 

Java Beginners

java io - Java Beginners
Java IO Streams  What is the Java IO Stream 

Java Beginners

date format - Java Beginners
date format  how to 45day in dd-mmm-yyyy date format.  Hi...-yyyy", Locale.US); Date d = sdf.parse(timestamp); Calendar cal..."; System.out.println("Date is : " + timestampToParse); Calendar cal = parseTimestamp 

Java Beginners

date format - Java Beginners
date format  How to convert yyyy-mm-dd to dd-mmm-yyyy  Hi... void main(String args[]) throws Exception{ Date todaysDate = new java.util.Date...-dd date is ==>"+formattedDate); Date date1 = formatter.parse 

Java Interview Questions

Java IO
Java IO  What an I/O filter 

Java Beginners

java IO
java IO  Write a Java program to accept a file name as command line argument. Append the string "File Modified by Programme" to the end of the same file and print the contents of the modified File 

Java Beginners

convert current date into date format
convert current date into date format  How to get current date and convert into date format in Java or PHP 

General

Simple Date Format Exception
pattern)-creates a SimpleDateFormat using the specified pattern and date format...)-creates a SimpleDateFormat using the given pattern and date format symbols... Format Exception Example In this program code we want to describe you the date 

Java Beginners

Date Format required to change in java
Date Format required to change in java  can we change the format of date like sql as per our requirements???If yes then please give the detail solution 

Java Beginners

java IO programing
java IO programing  how Java source file is used as input the program will echo lines 

Java Server Faces Questions

Java Date format - Java Server Faces Questions
Java Date format  Code to calculate days between two dates in format... dates in format(DD/MM/YYYY) import java.util.Date; import... static void main(String[] args) { //string containing date in one 

Java-Tutorials

Java String To Date
the conversion of Java string written into the specified format to a Java date object... Date classes using which we can manipulate with these objects in the Java... will be convert into Java date object. In this example we will first specify a date string 

Core Java

Java SimpleDateFormat Example
is being given which will demonstrate you about about how to format a date using... will specified a date format as a String and then we will format that date using...Java SimpleDateFormat Example In this section we will discuss about how 

Blog

Dateformat Example
Dateformat Example The Java Dateformat class is used to format the date/time... the report to format the date/time in required format. To format a date...: Dateformat Dateformat example Dateformat tutorial Date Formatter 

Java Beginners

core java ,io operation,calling methods using switch cases
core java ,io operation,calling methods using switch cases  How to create a dictionary program,providing user inputs using io operations with switch cases and providing different options for searching,editing,storing meanings 

Java Beginners

IO File - Java Beginners
IO File  Write a java program which will read an input file & will produce an output file which will extract errors & warnings. It shall exclude the standard errors & warnings. The standard errors & warnings you can find out 

Java Technology Tutorials

Formatting and Parsing a Date Using Default Formats
Formatting and Parsing a Date Using Default Formats In this section, you will learn how to format and parse a Date using default formats. Java has provide many classes to format a date. Here we are discussing default formats. The class 

Java-Tutorials

Java IO InputStream Example
Java IO InputStream Example In this section we will discuss about the InputStream in Java. An abstract class InputStream is a base class of all the byte...   Example : An example is being given here which demonstrates how 

Java-Tutorials

Java IO PrintWriter
Java IO PrintWriter In this tutorial we will learn about the the PrintWriter class in Java. java.io.PrintWriter class is used for format printing of objects... the PrintWriter in the Java applications. In this example I have created 

Java Beginners

IO concept
IO concept  Write a java program that moves the contents of the one file to another and deletes the old file.   Hi Friend, Try...!"); } } For more information, visit the following link: Java Move File Thanks 

General

Java Date
This example shows how to parsing date using Format class... This example shows how to format Date using SimpleDateFormat class... This example shows how to format Date using Format class. In this program we use 

Java Server Faces Questions

Regarding Date Format - Java Server Faces Questions
Regarding Date Format  How I can convert this(18-Aug-08) date format to Gregorian calendar date format?plz send me the syntax and code plz!!  hai,, http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f 

Java Server Faces Questions

Date format - Java Server Faces Questions
Date format  Hi All, I have field like Invoice Date is displaying a date like MMddyyyy HH:mm:ss format.i want to set format to MM//dd//yy. To set the format for the field, I believe you have to use the jsf 

Java Beginners

How to read the data in text file seperated by by ',' in java using IO Operations
How to read the data in text file seperated by by ',' in java using IO Operations  in Text file data like raju 45,56,67 ramu 46,65,78 raji 34,23,56 this is the student marks in text file.this data read and calculate 

Java Beginners

Java Date - Java Beginners
Java Date  I have to find the previous date's beginning time and end time in the long milliseconds format. for example today date is '23rd April... main(String[] args) { Date now = new Date(); DateFormat df   Hi friend 

Java Beginners

io - Java Beginners
. http://www.roseindia.net/java/ Thanks Amardeep 

General

Simple Date Format Example
Following is a simple date format example made using Format class. We have uses a pattern of special characters to date and time format. In this example... is a simple Date Format Example: import java.text.*; import java.util.*; public 

Java-Tutorials

Java IO SequenceInputStream Example
Java IO SequenceInputStream Example In this tutorial we will learn about...; started form the offset 'off'. Example : An example... or concatenate the contents of two files. In this example I have created two text 

Java Tips and Examples

Decimal Format Example
Decimal Format Example       In this example we are going to format a decimal value. In this example we are talking a double value. We are creating an object 

General

Date Format Example
Date Format Example       This example shows how to format Date using Format class. In this program we use a pattern of special characters to date and time format 

Java Beginners

convert date month and year into word using java
Basic format for Date and Month  convert the date, month,year into word like 12-3-2012 into twelve march two thousands twelve pls send the code write in java.   Visit Here 

Java Beginners

convert date month and year into word using java
Date Format in Jave  convert the date, month,year into word like 12-3-2012 into twelve march two thousands twelve pls send the code write in java.   Visit Here 

Java Tips and Examples

Convert Date To Calendar
;  In this example we are converting  date into Calendar. Here we are using format method to convert date into string.  We are using java.util. Calendar class in this example 

Java Technology Tutorials

Formatting a Number Using a Custom Format
Formatting a Number Using a Custom Format In this section, you will learn how to format a number using a custom format. A number can be formatted in different ways. Java has designed several classes to format the number. Using 

Java-Tutorials

Java FileOutputStream Example
Java FileOutputStream Example In this section we will discuss about the Java... the above example : 1. First compile the WriteFileOutputStreamExample.java using.... After successfully compilation execute the class by using java command 

Java Beginners

Simple IO Application - Java Beginners
Simple IO Application  Hi, please help me Write a simple Java application that prompts the user for their first name and then their last name. The application should then respond with 'Hello first & last name, what 

Date Calendar

java - Date Calendar
java   Using java how can i change the date format of the system from mm/dd/yy to dd/mm/yy. The code which i wrote is changing the format only on the console and not on the system's control panel.Can you suggest me anything 

Java-Tutorials

Java IO FileReader
Java IO FileReader In this tutorial we will learn about the FileReader class in Java. java.io.FileReader class is used to read the character streams. To read... you about how to use java.io.FileReader. In this example I have created a Java 

Java-Tutorials

Java: Kilometer to Miles - IO Class
Java NotesKilometer to Miles - IO Class 1 2 3 4 5 6.... double miles; // Number of miles. IOHandler io; //... Initialization io = new IOHandler 

Java-Tutorials

Java IO OutputStreamWriter
"); bw.newLine(); bw.write("Java IO OutputStreamWriter Example...Java IO OutputStreamWriter In this section we will learn about the Java... except this the FileOutputStream class is used. Using this example I have 

Java-Tutorials

Java IO PipedWriter
Java IO PipedWriter In this tutorial we will learn about the PipedWriter in Java. java.io.PipedWriter writes the characters to the piped output stream.... Syntax : public void write(int c) throws IOException Example Here 

Java-Tutorials

Java IO StringWriter
Java IO StringWriter In this section we will discussed about the StringWriter... in the Java program. In this example I have created a Java class named...[]) { String str = "Java StringWriter Example"; try 

Java-Tutorials

Java IO Reader
Java IO Reader In this section we will discuss about the Reader class in Java... skip(long n) throws IOException Example : An example of Reader class... and how the characters can be read from the stream. In this example I have created 

Java-Tutorials

Java IO PipedReader
Java IO PipedReader In this section we will discuss about the PipedReader in Java. java.io.PipedReader reads the characters from pipe. java.io.PipedWriter... boolean ready() throws IOException Example This is a very simple example which 

Java-Tutorials

Java IO Writer
Java IO Writer In this section we will discuss about the Writer class in Java... len) throws IOException Example To demonstrate how to use Writer to write into the output stream I am giving a simple example. In this example I have 

Date Calendar

ask java - Date Calendar
" + sdf.format(date)); //string containing date in one format String strDate1... { //create SimpleDateFormat object with source string date format... but in java i found too but i can't to join in another frame. And i want to ask how 

Java-Tutorials

Java IO PushbackReader
Java IO PushbackReader In this section we will discuss about the PushbackReader class in Java. PushbackReader is a class of java.io package that extends.... In this example I have created a simple Java class named 

Java-Tutorials

Java IO CharArrayWriter
Java IO CharArrayWriter In this tutorial we will learn about the CharArrayWriter in Java. java.io.CharArrayWriter extends the java.io.Writer.... : public void writeTo(Writer out) throws IOException Example This example 

General

Date Example
Date Example       In this section we are discussing about the specific date using the Date... are creating Date object that contains the current date and time by using the date 

Java Interview Questions

How to add a file in GZIP file format in Java programme.
How to add a file in GZIP file format in Java programme.  Hi please help me. How to add a file GZIP File format in Java program. If example... in Gzip file format. For details visit http://www.roseindia.net/java/examples 

Date Calendar

Using POI - Date Calendar
Using POI  What can i do with POI in Java and also give me an example of it.Thanks 

Java-Tutorials

Java IO FilterWriter
Java IO FilterWriter In this example we will discuss about the FilterWriter...(); bw.write("Java IO FilterWriter Example"); System.out.println("Data is written... an example is being given which demonstrates about how to use Java FilterWriter 

Java Beginners

how to get date format in string from date object containing real date in java
how to get date format in string from date object containing real date in java  i want to get data string format from date object where date object containing real date. date frequently vary in from of only month & year 

Java Beginners

how to get date format in string from date object containing real date in java
how to get date format in string from date object containing real date in java  i want to get data string format from date object where date object containing real date. date frequently vary in from of only month & year 

Java Beginners

How to format text file? - Java Beginners
/example/java/io/java-read-file-line-by-line.shtml Thanks...How to format text file?  I want the answer for following Query ***(Java code) How to open,read and format text file(notepad) or MS-word 

PHP Tutorial

date_parse_from_format
  date_parse_from_format date_parse_from_format function returns... about given date. Description on PHP Date Parse Format array date_parse_from_format ( string $format , string $date ) Parameters of Date Parse Function PHP 

MySQL

Date validation in JSP
Date validation in JSP       Example for validating date in a specified format in a JSP page This example illustrates how to use date validation in a JSP page. Here in this code we are using 

General

Set Data Format in Excel Using POI 3.0
Set Data Format in Excel Using POI 3.0   ... file using Java.  POI version 3.0 provides a new feature for manipulating various file formats based upon Microsoft's OLE 2 Compound Document format using 

Date Calendar

Java Date conversion - Date Calendar
Java Date conversion  How do I convert 'Mon Mar 28 00:00:00 IST 1983' which is a java.util.Date or String to yyyy/MM/dd date format in sql 

Java-Tutorials

Java ByteArrayOutputStream Example
Java ByteArrayOutputStream Example In this section we will discuss about the Java IO Byte Streams ByteArrayOutputStream. ByteArrayOutputStream... IOException Example : Here an example is being given which will demonstrate you 

Date Calendar

Date Formay - Date Calendar
Date Formay  Sir, How to comapare two different date format in java.  Hi friend, Code to compare two different date import...)) System.out.print("Current date(" + new SimpleDateFormat("dd/MM/yyyy"). format 

Java Beginners

Difference between Java IO Class - Java Beginners
Difference between Java IO Class  What is the difference in function between Two set of Stream class as mention below- 1)FileInputStream... information. http://www.roseindia.net/java/ Thanks 

Java Technology Tutorials

Formatting a Message Containing a Date
to format the message containing a date. Java has also provide a way to format... args). In the given example, we have used the instance method format() to format... also format the message with date in different languages. Here is the code 

Hibernate Questions

Hibernate Criteria Max Date Example
for finding max Date in Java program then check the following links: Example...Hibernate Criteria Max Date Example   How to write example program for finding the maximum date using Hibernate Criteria? Thanks   If you 

General

Java program to get current date
Java program to get current date now  ... date and time instance. For printing date in the specific format we have used...:mm:ss format. Here is the full example code of GetDateNow.java 

General

Simple date formatter example
Simple date formatter example       In this section of simple date formatter example we... class to convert the date into the specified format. There are various constructors 

Java Beginners

Save Java Textarea Content in Html Format using FileMenu
Save Java Textarea Content in Html Format using FileMenu  Hi.. How to save the textarea content to html format...Using FileMenu Option 

Java Beginners

Decimal Format Issue Java
Decimal Format Issue Java  Decimal Format Issue Java 

Java Beginners

how to covert JPG format to Binary formart using java code..
how to covert JPG format to Binary formart using java code..  convert JPG format to Binary formart How can i convert JPG format to Binary format using java code plz help me out 

Core Java

Java Calendar Example
The following Java Calendar Example will discuss java.util.Calender class...() method that print today's date. In this example we will subtract 2 years from... and object of SimpleDateFormat class, which is used to format the date and time 

Java3D Questions

want a program for date picker by using java swings
want a program for date picker by using java swings  to write a program for the date picker by using java swings.any one please help me by providing the code to this java date picker by using the java swings.previously a program 

General

Java Get Month from Date
month from the current date using Java Application Language.  You can see... Java Get Month from Date     ... of framework classes and utilities with date and time facilities in Java 

Java Beginners

Date Java - Java Beginners
Date Java  I'm using the eclipse software and I get an error for my...: public class Date { private int month; // 1-12 private int day; // 1-31... for day. public Date( int theMonth, int theDay, int theYear ) { if ( theMonth 

Java-Tutorials

Java FileInputStream
Java FileInputStream In this section we will discuss about the Java IO... of FileInputStream class. FileInputStream's object can be created using following its...) A FileInputStream is created for the specified file created using 

Java Beginners

How to convert EBCDIC format value into ASCII format value in java
How to convert EBCDIC format value into ASCII format value in java  how to convert EBCDIC data format into ASCII format data using java Use Case:I my file contains ASCII format values as well as EBCDIC format values.I need 

General

Convert String into date
in java. Example:  Code to convert String to Date in java. import... { //convert string to date with ddMMyyyy format example "20052013...Convert String into date In this example we are going to convert String 

General

Java Date Conversion
into string. In  this example we are using format method to convert date... Java Converts String into Date In this example we are going to convert...; date into long. In  this example we are using getTime() method to get 

Java Beginners

Parsing date in Java
Parsing date in Java  How can i parse the date in Java in a simple format..?   SimpleDateFormat parserSDF=new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy 

General

Working on Rich Text Format on Slide Using Java
Working on Rich Text Format on Slide Using Java... a slide then we will learn how we can work on rich text using java. In this example we are creating an object of  SlideShow after that we are using 

Java Technology Tutorials

Formatting and Parsing a Date for a Locale
to format and parse a date for a locale. Java has provide the utility.... Here we are going to format and parse the date in French language. For this we... example, we have used Format and SimpleDateFormat class for this purpose. We have 

JSP Tutorials

Assing Date into Cells
in  excel sheet using java .You have create any number of  cells... the format for cell style. To add date into cells, create new date object... assing Date into cells      

Java-Tutorials

Java IO StringReader
Java IO StringReader In this section we will discuss about the StringReader... in Java. In this example I have created a Java class named...; String str = "\n Java IO StringReader \n"; try 

Advertisements Advertisements
 

 

 

DMCA.com