Reading contents from text files all at once using Apache Commons IO

The same functionality described in the previous recipe can be achieved using Apache Commons IO API.

Getting ready

In order to perform this recipe, we will require the following:

  1. In this recipe, we will be using a Java library from Apache named Commons IO. Download the version of your choice from here: https://commons.apache.org/proper/commons-io/download_io.cgi
  2. Include the JAR file in your project an external JAR in Eclipse.

How to do it...

  1. Say, you are trying to read the contents of a file located in your C:/ drive named dummy.txt. First, you need to create a file object for accessing this file as follows:
            File file = new File("C:/dummy.txt");  
    
  2. Next, create a string object to hold ...

Get Java Data Science Cookbook now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.