tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Commons IO > Basic > Read File As List of Strings

Read File As List of Strings 

Apache Commons IO is a java library with simple IO utilities and filters. This requires the library commons-io-2.1.jar to be in classpath. The following example shows using FileUtils.readLines() API. It returns the file content as list of strings by reading the file line by line.

File Name  :  C:/Test/rule_engine_names.txt

File Name  :  
com/bethecoder/tutorials/commons_io/tests/ReadFileAsStringList.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.commons_io.tests;

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

import org.apache.commons.io.FileUtils;

public class ReadFileAsStringList {

  /**
   @param args
   @throws IOException 
   */
  public static void main(String[] argsthrows IOException {
    File file = new File("C:/Test/rule_engine_names.txt");
    
    for (String line : FileUtils.readLines(file, "UTF-8")) {
      System.out.println(line);
    }
  }
}
   

It gives the following output,
BizTalk
Blaze Advisor
Jess
JRules
OpenRules
PegaRules
RulesPower



 
  


  
bl  br