APACHE COMMONS / CATATAN</>↗Apache Commons10 Jul 2008
The File Transfer Protocol (FTP) is a standard network protocol used to transfer computer files between a client and server on a computer network. The example below shows you how to connect to an FTP server. In this example we are using the FTPClient class of the Apache Commons Net library. To connect to the […]
APACHE COMMONS / CATATAN</>↗Apache Commons10 Jul 2008
This example demonstrates a touch command just like Unix touch command. If the file to be touched doesn’t exist, a new empty file will be created. package org.kodejava.commons.io; import org.apache.commons.io.FileUtils; import java.io.File; import java.io.IOException; public class TouchFileExample { public static void main(String[] args) { try { File file = new File("Touch.dat"); // Touch the file. […]
APACHE COMMONS / CATATAN</>↗Apache Commons09 Jul 2008
Using the FileUtils.deleteDirectory() from the Apache Commons IO library, we can simplify the process of deleting directory and everything below it recursively. package org.kodejava.commons.io; import org.apache.commons.io.FileUtils; import java.io.File; import java.io.IOException; public class DeleteDirectory { public static void main(String[] args) { try { File directory = new File("F:/Temp"); // Deletes a directory recursively. When a deletion […]
APACHE COMMONS / CATATAN</>↗Apache Commons05 Jul 2008
This example demonstrates how to create a human-readable file size using the FileUtils class of the Apache Commons IO library. The byteCountToDisplaySize() method take the file size in bytes and return a human-readable display of the file size in bytes, kilobytes, megabytes, gigabytes, etc. package org.kodejava.commons.io; import org.apache.commons.io.FileUtils; import java.io.File; public class ReadableFileSize { public […]
BASIC / CATATAN</>↗Basic03 Jul 2008
The @SuppressWarnings annotation tells the compiler to suppress the warning messages it normally shows during compilation time. It has some level of suppression to be added to the code, these level including: all, deprecation, fallthrough, finally, path, serial and unchecked. package org.kodejava.basic; import java.util.Calendar; import java.util.Date; public class SuppressWarningsExample { @SuppressWarnings(value={"deprecation"}) public static void main(String[] […]
BASIC / CATATAN</>↗Basic29 Jun 2008
We use the @Override annotation as part of method declaration. The @Override annotation is used when we want to override methods and want to make sure have overridden the correct methods. As the annotation name we know that there should be the same method signature in the parent class to override. That means using this […]