Home » Core Java » util » Page 28

util

Compare Dates with after method

This is an example of how to compare Dates with after(Object when) method of the Calendar class. Comparing a Calendar object to another using after(Object when) method of Calendar implies that you should: Use getInstance() API method of Calendar, in order to get two Calendar objects, using the default time zone and locale. Use set(int field, int value) API method ...

Read More »

Add/Subtract Hours from Date with Calendar

In this example we shall show you how to add and substract Hours from a Date with the Calendar class. Using this abstract class we can convert between a specific instant in time and a set of calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR. To add and substract Hours from Date with the Calendar one should perform the following ...

Read More »

Add/Subtract Months from Date with Calendar

With this example we are going to demonstrate how to add and subtract Months from a Date using the Calendar class, that allows us to convert between a specific instant in time and a set of calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR. In short, to add and subtract Months from a Date using the Calendar class you should: ...

Read More »

Add/Subtract Days from Date with Calendar

This is an example of how to add and subtract Days from a Date using the Calendar, that provides methods to convert between a specific instant in time and a set of calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR. Adding and subtracting Days from a Date using the Calendar implies that you should: Create a new Calendar object, using ...

Read More »

Create zip file from directory recursively with ZipOutputStream

In this example we shall show you how to create a zip file from a directory recursively, using ZipOutputStream. We have implemented a method to write a File to a ZipFile, with a ZipOutputStream. It is void addDirToArchive(ZipOutputStream zos, File srcFile). The steps of this method are described below: The method gets the array of Files of abstract pathnames denoting ...

Read More »

Create zip file from multiple files with ZipOutputStream

With this example we are going to demonstrate how to create a zip file from multiple Files with ZipOutputStream, that implements an output stream filter for writing files in the ZIP file format. In short, to create a zip file from multiple Files with ZipOutputStream you should: Create a FileOutputStream to write to the file with the specified name, that ...

Read More »

Create zip file from single file with ZipOutputStream

This is an example of how to create a zip file from a single File with ZipOutputStream. The ZipOutputStream class implements an output stream filter for writing files in the ZIP file format. Creating a zip file from a single File with ZipOutputStream implies that you should: Create a FileOutputStream to write to the file with the specified name, that ...

Read More »

Create zip file from directory with ZipOutputStream

In this example we shall show you how to create a zip file from a directory with ZipOutputStream class, that is an output stream filter for writing files in the ZIP file format. To create a zip file from a directory with ZipOutputStream one should perform the following steps: Create a FileOutputStream to write to the file with the specified ...

Read More »

Extract zip file with subdirectories

With this example we are going to demonstrate how to extract from a ZipFile With Subdirectories. In short, to extract from a ZipFile With Subdirectories you should: Create a new File instance by the given pathname of the file. Create a directory with the same name to which the contents will be extracted, using mkdir() API method of File. Create ...

Read More »

Search file in a zip file

This is an example of how to search a File in a zip file, using the ZipFile class. Searching a File in a zip file implies that you should: Create a new ZipFile and open it for reading. Get the enumeration of the ZipFile entries, with entries() API method of ZipFile and iterate through each one of them. For each ...

Read More »