tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Tools and Libs > Commons IO > Basic > Write Lines to File

Write Lines to File 

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.writeLines() API.

File Name  :  
com/bethecoder/tutorials/commons_io/tests/WriteLinesToFile.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.commons_io.tests;

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

import org.apache.commons.io.FileUtils;

public class WriteLinesToFile {

  /**
   @param args
   @throws IOException 
   */
  public static void main(String[] argsthrows IOException {
    File file = new File("C:/Test/abc.txt");
    
    List<String> lines = Arrays.asList("ONE""TWO""THREE""FOUR");
    String lineSep = "\n";
    
    FileUtils.writeLines(file, lines, lineSep, true);
  }
}
   

It gives the following output,
File Name  :  C:/Test/abc.txt


                    Print

   



Books Recommendation

 
 
bl  br