Package com.fabelist.resource.util

Source Code of com.fabelist.resource.util.FileUtil

package com.fabelist.resource.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;

import javax.imageio.stream.FileImageInputStream;

/**
* @author Hasan Keklik
*/
public class FileUtil {

  public static void copy(File curFile, File destFile) throws IOException {
    FileImageInputStream fis;
    FileOutputStream fos;
    byte[] buffer = new byte[4096];
    try {
      fos = new FileOutputStream(destFile);
      fis = new FileImageInputStream(curFile);
      int length;
      while ((length = fis.read(buffer)) > 0) {
        fos.write(buffer, 0, length);
      }
      fis.close();
      fos.close();
    } finally {
      fis = null;
      fos = null;
      buffer = null;
    }

  }

  public static String readFileAsString(String filePath)
      throws java.io.IOException {
    StringBuffer fileData = new StringBuffer(1000);
    BufferedReader reader = new BufferedReader(new FileReader(filePath));
    char[] buf = new char[1024];
    int numRead = 0;
    while ((numRead = reader.read(buf)) != -1) {
      String readData = String.valueOf(buf, 0, numRead);
      fileData.append(readData);
      buf = new char[1024];
    }
    reader.close();
    return fileData.toString();
  }

}
TOP

Related Classes of com.fabelist.resource.util.FileUtil

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.