In this post under Java, I will show with example how to uncompress a gzip format file. For decompressing a gzip file, we will use java provided “GZIPInputStream” class. Below is the main code for your reference Main class 1 package zip; 2 3 import java.io.File; 4 import java.io.FileInputStream; 5 import java.io.FileOutputStream; 6 import java.io.IOException;…… Continue reading Uncompressing a gzip file
Category: Java
Compressing a file in gzip format
In this post under Java, I will show with example how to compress a single file in gzip format. For compressing a file in gzip format, we will use java provided “GZIPOutputStream” class. Below is the main code for your reference Main Class 1 package zip; 2 3 import java.io.File; 4 import java.io.FileInputStream; 5 import…… Continue reading Compressing a file in gzip format
Converting Date instance to Instant instance
In this post under DateTime, I will show how to convert an instance of “Date” class to “Instant” instance. Below is the code to that will do the conversion. Date date = new Date(); Instant instant = date.toInstant(); As shown in the above code snippet, first we create a “Date” instance and store in “date”…… Continue reading Converting Date instance to Instant instance
Converting Instant instance to Date instance
In this post under DateTime, I will show how to convert an instance of “Instant” class to “Date” instance. Below is the code to that will do the conversion. Instant instant = Instant.now(); Date date = Date.from(instant); “now” static method of “Instant” class will return an “Instant” instance representing the current date time. Then we…… Continue reading Converting Instant instance to Date instance
Serializing and De-Serializing Date object to and from a custom pattern
In this post under Java, I will show with example how to serialize and de-serialize Date object using a custom pattern. In the previous post, we used “SimpleDateFormat” class to serialize and de-serialize Date object using a pattern obtained based on system default locale. This pattern was figured out by Java and was not provided…… Continue reading Serializing and De-Serializing Date object to and from a custom pattern
Serializing and De-Serializing Date object to and from pattern
In this post, I will show with example how to serialize and deserialize Date object. Java provides “SimpleDateFormat” class to serialize and deserialize Date objects. Below is an example Main class 1 package datetime; 2 3 import java.text.ParseException; 4 import java.text.SimpleDateFormat; 5 import java.util.Date; 6 7 public class Example1 { 8 public static void main(String[]…… Continue reading Serializing and De-Serializing Date object to and from pattern
Comparing two arrays for equality
In this post under Java, I will show with example how to check whether two arrays are equal or not. The class Arrays under java.util package has “equals” static method which takes two arrays as arguments and compare their contents to check whether they are same. Below is the code showing an example Main 1…… Continue reading Comparing two arrays for equality
Getting a list of ClassPath scanned by a Java Program
In this post under Java, I will post the code which will list all the paths a Java Program uses to search for linked jars and resources. Below is the main method Main class 1 package classloader; 2 3 import java.net.URL; 4 import java.net.URLClassLoader; 5 6 public class ClassPath { 7 public static void main(String[]…… Continue reading Getting a list of ClassPath scanned by a Java Program
Externalizing the logger and handler configuration to properties file
In all my previous posts under java logging, I have configured logger and handler programmatically. We can externalize those configurations to properties file also. The advantage of this approach is that we can change configurations at any time without recompiling java class. In this post I will show with example how to do that. Let’s…… Continue reading Externalizing the logger and handler configuration to properties file
Setting Log Levels for Logger and Handler
In this post under Java Logging, I will explain with example how to set log levels for Logger and Handler implementations. Please not the log level of Logger and Handler should be same otherwise some messages will not be logged by the handler. We set the log levels by calling “setLevel” method available on Logger…… Continue reading Setting Log Levels for Logger and Handler