package me.chaopeng.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

/**
 * 文件工具类
 * @author chao
 */
public class FileUtils {

	private static Logger logger = LoggerFactory.getLogger(FileUtils.class);

	/**
	 * read a file to a string
	 */
	public static String readFile(String fileName) {
		BufferedReader br = null;
		try {
			br = new BufferedReader(new FileReader(fileName));
			StringBuilder sb = new StringBuilder();
			String line = br.readLine();

			while (line != null) {
				sb.append(line);
				sb.append("\n");
				line = br.readLine();
			}
			return sb.toString();
		} catch (Exception e) {
			logger.error("!!!", e);
		} finally {
			CloseUtils.close(br);
		}

		return null;
	}
}

@@ -98,77 +98,9 @@
 .io.
-BufferedReader;%0Aimport java.io.FileReader;%0Aimport java.io.IOException
+*
 ;%0A%0A/
@@ -111,16 +111,19 @@
 * %E6%96%87%E4%BB%B6%E5%B7%A5%E5%85%B7%E7%B1%BB%0A
+ *%0A
  * @auth
@@ -315,20 +315,20 @@
 ing file
-Name
+Path
 ) %7B%0A%09%09Bu
@@ -409,12 +409,12 @@
 file
-Name
+Path
 ));%0A
@@ -727,11 +727,1215 @@
 null;%0A%09%7D
+%0A%0A%09/**%0A%09 * read a file to a string%0A%09 */%0A%09public static String readFile(File file) %7B%0A%09%09BufferedReader br = null;%0A%09%09try %7B%0A%09%09%09br = new BufferedReader(new FileReader(file));%0A%09%09%09StringBuilder sb = new StringBuilder();%0A%09%09%09String line = br.readLine();%0A%0A%09%09%09while (line != null) %7B%0A%09%09%09%09sb.append(line);%0A%09%09%09%09sb.append(%22%5Cn%22);%0A%09%09%09%09line = br.readLine();%0A%09%09%09%7D%0A%09%09%09return sb.toString();%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09logger.error(%22!!!%22, e);%0A%09%09%7D finally %7B%0A%09%09%09CloseUtils.close(br);%0A%09%09%7D%0A%0A%09%09return null;%0A%09%7D%0A%0A%09/**%0A%09 * get md5 of file%0A%09 */%0A%09public static String fileMD5(String filePath) %7B%0A%09%09FileInputStream fis = null;%0A%09%09String md5 = null;%0A%09%09try %7B%0A%09%09%09fis = new FileInputStream(new File(filePath));%0A%09%09%09md5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(fis);%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09logger.error(%22!!!%22, e);%0A%09%09%7D finally %7B%0A%09%09%09CloseUtils.close(fis);%0A%09%09%7D%0A%09%09return md5;%0A%09%7D%0A%0A%09/**%0A%09 * get md5 of file%0A%09 */%0A%09public static String fileMD5(File file) %7B%0A%09%09FileInputStream fis = null;%0A%09%09String md5 = null;%0A%09%09try %7B%0A%09%09%09fis = new FileInputStream(file);%0A%09%09%09md5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(fis);%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09logger.error(%22!!!%22, e);%0A%09%09%7D finally %7B%0A%09%09%09CloseUtils.close(fis);%0A%09%09%7D%0A%09%09return md5;%0A%09%7D%0A%0A
 %0A%7D%0A

add file md5 method