APACHE COMMONS / CATATAN</>↗Apache Commons28 Mar 2010
The code snippet below shows you how to use the FileUtils.copyURLToFile(URL, File) method of the Apache Commons IO library to help you to copy the contents of a URL directly into a file. package org.kodejava.commons.io; import org.apache.commons.io.FileUtils; import java.io.File; import java.io.IOException; import java.net.URI; import java.net.URL; public class URLToFile { public static void main(String[] args) { […]
APACHE COMMONS / CATATAN</>↗Apache Commons26 Mar 2010
The getFreeSpaceKb(String path) method in the FileSystemUtils class can help you to calculate the free space of a drive or volume in kilobytes. Beside using commons-io solution, you can use the File.getFreeSpace() method call provided in the Java 1.6 API. You can find an example of it in the following link: How do I get […]
APACHE COMMONS / CATATAN</>↗Apache Commons22 Des 2009
The code below show you how to use the Apache Commons-Lang RandomStringUtils class to generate some random string data. package org.kodejava.commons.lang; import org.apache.commons.lang3.RandomStringUtils; public class RandomStringUtilsDemo { public static void main(String[] args) { // Creates a 64-chars length random string of number. String result = RandomStringUtils.random(64, false, true); System.out.println("random = " + result); // Creates […]
APACHE COMMONS / CATATAN</>↗Apache Commons11 Des 2009
The following example shows you how to read file contents into byte array. We use the IOUtils class of the Apache Commons IO library. package org.kodejava.commons.io; import org.apache.commons.io.IOUtils; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; public class FileToByteArray { public static void main(String[] args) { File file = new File("README.md"); try { InputStream is […]
APACHE COMMONS / CATATAN</>↗Apache Commons07 Sep 2009
We can use the code below to convert the content of an InputStream into a String. At first, we use FileInputStream create to a stream to a file that going to be read. IOUtils.toString(InputStream input, String encoding) method gets the content of the InputStream and returns a string representation of it. package org.kodejava.commons.io; import org.apache.commons.io.IOUtils; […]
APACHE COMMONS / CATATAN</>↗Apache Commons03 Sep 2009
This example using the Apache Commons FileUpload library to create a simple application for uploading files. The program is divided into two parts, a form using JSP and a servlet for handling the upload process. To run the sample you need to download the Commons FileUpload and Commons IO get the latest stable version. The […]