how to use FileUtils in java

add this dependency in pom file

<!–appache common IO –>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>

package org.kodejava.sample.commons.io;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;

public class ReadFileToStringSample
{
    public static void main(String[] args)
    {
        // In this example we use FileUtils class from Apache
        // Commons IO (commons.io) to read the content of a 
        // file. FileUtils have two static methods called
        // readFileToString(File file) and readFileToString(
        // File file, String encoding) that we can user.

        // Here we create an instance of File to hold our
        // sample.txt file.
        File file = new File("sample.txt");

        try
        {
            // Read the entire contents of sample.txt
            String content = FileUtils.readFileToString(file);

            // For shake of this example we show the file content here.
            System.out.println("File content: " + content);
        } catch (IOException e)
        {
            e.printStackTrace();
        }
    }
}
Advertisements

About lorddisk

WebCenter Content, WebCenter Portal, WebCenter Sites,Weblogic, Identity and Access Management (IAM),SSO,OAM,OIM,OAAM,OUD, OPAM,OID, OVD ,Oracle API Gateway ,OBIEE,OEDQ, Oracle ADF, Oracle SOA,J2EE, CackePHP ,PHP,J2SE,J2EE,Spring,Hibernate,JQuery,CSS,Java Script ,Joomla,Drupal,Worpress
This entry was posted in java. Bookmark the permalink.

One Response to how to use FileUtils in java

  1. This is very interesting, You are a very skilled blogger.
    I’ve joined your feed and look forward to seeking more of your great post. Also, I’ve shared your website in my social networks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s