In this tutorial we are going to see how you can compress a File in Java using the GZIP compression method. So, to perform File compression using GZIP in Java, you have to: Create a FileOutputStream to the destination file, that is the file path to the output compressed file. Create a GZIPOutputStream to the above FileOutputStream. Create a FileInputStream ...
Read More »Home »
How to Write an Object to File in Java
On this tutorial we are going to see how you can store an object to a File in your File system in Java. Basically to perform basic IO operations on object, the class of the object has to implement the Serializable interface. This gives the basic interface to work with IO mechanisms in Java. In short, in order to write ...
Read More »Get free disk space in Java example
With this tutorial we are going to see how to use the File class in order to get the size of certain disk partitions in your file system. You can use: getTotalSpace() to get the total capacity of the disk partition you want. getFreeSpace() to get the free space of the disk partition. getUsableSpace() to get the usable space in ...
Read More »Generate a File Checksum value in Java
In this tutorial we are going to see how to generate a file’s Checksum value in Java using the SHA-1 hash function. If you are working on your applications security specs it might be useful to consider using checksums to improve the security and integrity of file transfer or file sharing actions. In short, the basic steps one should take ...
Read More »Move Files in Java example
In this example we are going to see how you can move a file to a new location in your File Path. In Java, there is no generic function you can use to do that. Nevertheless, you can use two ways to perform this operation: Use the renameTo function of the File class to do it. Copy the the File ...
Read More »Find files with certain extension only using FilenameFilter in Java
In this tutorial we are going to show you how to use the FilenameFilter interface in Java in order to list all the file with a certain property in their names. In this example for instance, we just want to print all the text files in a specific directory, hence the files ending with the “.txt” extension. Instances of classes that implement ...
Read More »Delete files with certain extension only using FilenameFilter in Java
In this tutorial we are going to show you how to use the FilenameFilter interface in Java in order to list all the file with a certain property in their names. In this example for instance, we want to delete all the text files in a specific directory, hence the files ending with “.txt” extension. Instances of classes that implement ...
Read More »Append content to file in Java example
With this tutorial we shall show you how to use FileWriter and BufferedReader classes in odrer to append content to a file using Java. The idea is very simple.You have an already created File that has some content in it and you want to write new content at the end of the existing one. In order to do that we ...
Read More »Write file with BufferedWriter example
With this tutorial we shall show you how to use BufferedWriter to write in a simple text file. It is particularly useful to work with BufferedWriter especially when you want to write an array and generally character data to a file. Let’s see the code: package com.javacodegeeks.java.core; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; public class ...
Read More »Read file with BufferedReader example
In this example we are going to see how to use use the BufferedReader class in Java in order to read a simple text file. In Java, there is a number of ways that you can use to read a file, but the BufferedReader class offers one the most efficient and easy to handle tools. Note that the BufferedReader class can ...
Read More »