FileUtils.java :  » RSS » androidnews » vn » evolus » droidreader » util » Android Open Source

Android Open Source » RSS » androidnews 
androidnews » vn » evolus » droidreader » util » FileUtils.java
package vn.evolus.droidreader.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.channels.FileChannel;

public class FileUtils {
  public static void copyFile(File sourceFile, File destFile) throws IOException {
    if(!destFile.exists()) {
      destFile.createNewFile();
    }
  
    FileChannel source = null;
    FileChannel destination = null;
    try {
      source = new FileInputStream(sourceFile).getChannel();
      destination = new FileOutputStream(destFile).getChannel();
      destination.transferFrom(source, 0, source.size());
    } finally {
      if(source != null) {
        source.close();
      }
      if(destination != null) {
        destination.close();
      }
    }
  }
  
  public static void save(String content, String fileName) throws IOException {
    FileOutputStream os = new FileOutputStream(fileName);
    OutputStreamWriter writer = new OutputStreamWriter(os);
    writer.write(content);
    os.flush();
    os.close();
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.