tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Google Guava > IO > Read File Line by Line

Read File Line by Line 

Google Guava is a java library with lot of utilities and reusable components. This requires the library guava-10.0.jar to be in classpath. The following example shows using Files.readLines() API.

File Name  :  abcd.txt

File Name  :  
com/bethecoder/tutorials/guava/io_tests/ReadLineByLineTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.guava.io_tests;

import java.io.File;
import java.io.IOException;
import java.util.List;

import com.google.common.base.Charsets;
import com.google.common.io.Files;

public class ReadLineByLineTest {

  /**
   @param args
   @throws IOException 
   */
  public static void main(String[] argsthrows IOException {
    File file = new File("C:\\abcd.txt");
    List<String> lines = Files.readLines(file, Charsets.UTF_8);
    for (String line : lines) {
      System.out.println(line);
    }
  }
}
   

It gives the following output,
ABCD
ABCD
ABCD
ABCD



 
  


  
bl  br