CORE API / CATATAN</>↗Core API23 Jul 2008
In this example you’ll see the utilization of SimpleDateFormat class for comparing two dates for equality. We convert the date object into string using the DateFormat instance and then compare it using String.equals() method. package org.kodejava.util; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class ComparingDate { public static void main(String[] args) { // […]
APACHE COMMONS / CATATAN</>↗Apache Commons20 Jul 2008
This example demonstrates how we can use the FileUtils class listFiles() method to search for a file specified by their extensions. We can also define to find the file recursively deep down into the subdirectories. package org.kodejava.commons.io; import org.apache.commons.io.FileUtils; import java.io.File; import java.util.Collection; public class SearchFileRecursive { public static void main(String[] args) { File root […]
APACHE COMMONS / CATATAN</>↗Apache Commons19 Jul 2008
This example demonstrates how to delete file from FTP server. package org.kodejava.commons.net; import org.apache.commons.net.ftp.FTPClient; import java.io.IOException; public class FTPDeleteDemo { public static void main(String[] args) { FTPClient client = new FTPClient(); try { client.connect("ftp.example.com"); client.login("demo", "password"); // Delete file on the FTP server. When the FTP delete // process completes, it returns true. String filename […]
APACHE COMMONS / CATATAN</>↗Apache Commons18 Jul 2008
This example demonstrates how to retrieve a list of files from FTP server. First we create an instance of org.apache.commons.net.ftp.FTPClient. Connect to the FTP server and login with your username and password. The listFiles() method of the FTPClient return the list of filenames contained in the current working directory. null if the list could not […]
APACHE COMMONS / CATATAN</>↗Apache Commons14 Jul 2008
This example demonstrates how to upload file to FTP server. package org.kodejava.commons.net; import org.apache.commons.net.ftp.FTPClient; import java.io.IOException; import java.io.InputStream; public class FTPUploadDemo { public static void main(String[] args) { FTPClient client = new FTPClient(); String filename = "data.txt"; // Read the file from the resources folder. ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); try (InputStream is = classLoad...
APACHE COMMONS / CATATAN</>↗Apache Commons11 Jul 2008
This example demonstrates how to download a file from FTP server. To download a file, we first connect to the FTP server and then login by supplying the username and password. To download the file we call retrieveFile() method of the FTPClient object. This method takes two parameters, the remote filename and an OutputStream of […]