APACHE COMMONS / CATATAN</>↗Apache Commons09 Jan 2012
The code snippet below uses the FileUtils.toFile(URL) method that can be found in the Apache Commons IO library to convert a URL into a File. The url protocol should be file or else null will be returned. package org.kodejava.commons.io; import org.apache.commons.io.FileUtils; import java.io.File; import java.net.URI; import java.nio.charset.StandardCharsets; import java.util.Objects; public class URLToFileObject { public static […]
APACHE COMMONS / CATATAN</>↗Apache Commons10 Agt 2011
This example shows you how to create a connection pool implementation using the Apache Commons DBCP library. package org.kodejava.commons.dbcp; import org.apache.commons.dbcp2.*; import org.apache.commons.pool2.impl.GenericObjectPool; import org.apache.commons.pool2.impl.GenericObjectPoolConfig; import javax.sql.DataSource; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; public class ConnectionPoolExample { private static final String...
APACHE COMMONS / CATATAN</>↗Apache Commons10 Agt 2011
This example demonstrates how to use the BasicDataSource class of Apache Commons DBCP to create a basic requirements for database connection. The configuration of the data source can be defined using some property method provided by this class. The basic properties are the driver classname, connection url, username and password. After the datasource ready we […]
APACHE COMMONS / CATATAN</>↗Apache Commons01 Jun 2011
This example show you how to capitalize a string. We use methods from WordUtils class provided by the Apache commons-text;. We can use the WordUtils.capitalize(str) or WordUtils.capitalizeFully(str). Let’s see an example below: package org.kodejava.commons.text; import org.apache.commons.text.WordUtils; public class WordCapitalize { public static void main(String[] args) { // Capitalizes all the whitespace separated words in a […]
APACHE COMMONS / CATATAN</>↗Apache Commons31 Mar 2010
Below is an example to move one directory with all its child directory and files to another directory. We can use the FileUtils.moveDirectory() method to simplify the process. package org.kodejava.commons.io; import org.apache.commons.io.FileUtils; import java.io.File; import java.io.IOException; public class DirectoryMove { public static void main(String[] args) { String source = "F:/Temp/source"; File srcDir = new File(source); […]
APACHE COMMONS / CATATAN</>↗Apache Commons31 Mar 2010
To copy a directory with the entire child directories and files we can use a handy method provided by the Apache Commons IO FileUtils.copyDirectory(). This method accepts two parameters, the source directory and the destination directory. The source directory should be available while if the destination directory doesn’t exist, it will be created. package org.kodejava.commons.io; […]