APACHE COMMONS / CATATAN</>↗Apache Commons12 Mei 2006
In this example, we are going to use the Apache Commons IO library to get or calculate the total size of a directory. The FileUtils class provided by the Commons IO can help us to achieve this goal. The first method that we can use is the FileUtils.sizeOfDirectory(), it calculates the size of a directory […]
APACHE COMMONS / CATATAN</>↗Apache Commons10 Mei 2006
The following example show how to use the Apache Commons IO library to read a text file line by line to a List of String. In the code snippet below we will read the contents of a file called sample.txt using FileUtils class. We use FileUtils.readLines() method to read the contents line by line and […]
APACHE COMMONS / CATATAN</>↗Apache Commons05 Mei 2006
In this example we use FileUtils class from Apache Commons IO to read the content of a file. FileUtils have two static methods called readFileToString(File) and readFileToString(File, String) that we can use. An example to read file contents and return the result as a string can be seen below. package org.kodejava.commons.io; import org.apache.commons.io.FileUtils; import java.io.File; […]
ZIP AND GZIP / CATATAN</>↗Zip and GZIP05 Mei 2006
package org.kodejava.util.zip; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; public class ZipFileExample { public static void main(String[] args) { try { // Create an instance of ZipFile to read a zip file // called sample.zip ZipFile zip = new ZipFile(new File("data.zip")); // Here we start to iterate each […]
BASIC / CATATAN</>↗Basic04 Mei 2006
Autoboxing is a new feature offered in the Tiger (1.5) release of Java SDK. In short auto boxing is a capability to convert or cast between object wrappers (Integer, Long, etc) and their primitive types. Previously when placing primitive data into one of the Java Collection Framework object we have to wrap it to an […]
CORE API / CATATAN</>↗Core API03 Mei 2006
The following code snippet show you how to copy a file using the NIO API. The NIO (New IO) API is in the java.nio.* package. It requires at least Java 1.4 because the API was first included in this version. The JAVA NIO is a block based IO processing, instead of a stream based IO […]