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

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

File Name  :  
com/bethecoder/tutorials/commons_io/tests/WriteFile.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 WriteFile {

  /**
   @param args
   @throws IOException 
   */
  public static void main(String[] argsthrows IOException {
    File fromFile = new File("C:/Test/rule_engine_names.txt");
    String fileContent = FileUtils.readFileToString(fromFile);
    
    File toFile = new File("C:/Test/rule_engine_names2.txt");
    FileUtils.write(toFile, fileContent, "UTF-8");
    System.out.println("Successfully written the file");
  }
}
   

It gives the following output,
Successfully written the file



 
  


  
bl  br