In this post under Apache Commons IO, I will show with example the purpose of static method “copyLarge” available in “IOUtils” class. In our previous post under Apache Commons IO, we already covered “copy” method available in “IOUtils” class. The purpose of both the methods is same i.e., copy the contents of one file into…… Continue reading IOUtils copyLarge method
Category: IO Utils
IOUtils writeLines method
In this post under Apache Commons IO, I will show with example the purpose of “writeLines” static method available in “IOUtils” class “writeLines” method takes a list of Objects and writes them to outputstream or writer. For each object to be written, it calls its “toString” method to get the String representation of the object…… Continue reading IOUtils writeLines method
Skipping data while reading
In this post under Apache Commons IO, I will explain with example how to skip certain amount data while reading. We can use static “skip” method available as part of “IOUtils” class. This method takes two arguments1) the reader from where it is reading data. The reader can be byte or character stream2) the number…… Continue reading Skipping data while reading
Reading file contents as a List of Strings
In this post under Apache Commons IO, I will show with example how to read file contents into a List of Strings. To implement this requirement, the library class “IOUtils” provide with a method named “readLines” This method takes a “FileReader” instance as an argument and return a list of Strings, where each String represents…… Continue reading Reading file contents as a List of Strings
Reading classpath file contents
In this post under Apache Commons IO, I will show with example how to read the contents of file present in your projects classpath. “IOUtils” class provides a static method named “resourceToString”. This method reads the contents of the file and return a String object. This method takes 3 arguments1) the file name2) the ClassLoader…… Continue reading Reading classpath file contents
Reading classpath file contents as bytes
In this post under Apache Commons IO, I will show with example how to read the contents of file present in your projects classpath as bytes. “IOUtils” class provides a static method named “resourceToByteArray”. This method reads the contents of the file as bytes. This method takes two arguments1) the file name2) the ClassLoader instance…… Continue reading Reading classpath file contents as bytes
Reading file contents using Iterator
In this post under Apache Commons IO, I will show with example how to read file contents using Iterator. “IOUtils” provides a static method named “lineIterator” which reads the file and returns an “Iterator” object. Each item returned by this iterator represent a line in the file. Using the “Iterator” object we can iterate the…… Continue reading Reading file contents using Iterator
String to InputStream conversion
In this post under Apache Commons IO, I will show with example how to convert a String to InputStream. “IOUtils” class in Apache Commons IO framework provides a method named “toInputStream” which converts a String to InputStream. This method takes two arguments1) instance of String class2) Charset type Below is the main class showing how…… Continue reading String to InputStream conversion
Getting URL of classpath resource
In this post under Apache Commons IO, I will show with example how to get URL of a resource present in application classpath. “IOUtils” class provides a static method “resourceToURL” which takes the resource name and the classloader as arguments and returns url of the resource. Below is the main class showing how to use…… Continue reading Getting URL of classpath resource
File copy example
In this post under Apache Commons IO, I will explain with example how to copy a file. Apache provides “IOUtils” static class which has static method “copy”. We can use this “copy” method to copy files. Below is the complete main code for your reference. Main class package ioutils; import org.apache.commons.io.IOUtils; import java.io.File; import java.io.FileReader;…… Continue reading File copy example