
package com.trs.project.util;

import java.io.*;

/**
 * 
 * Created by CXC on 2017/6/5.
 * 
 */

public class Log {
	public static void Logger(String dirNames, String content){
		File file = new File(dirNames);
		if(!file.exists())file.mkdirs();
		String path = dirNames;
		FileWriter fw = null;
		try {
			File F = new File(path);
			// 如果文件不存在,就动态创建文件
			if (!F.exists()) {
				F.createNewFile();
			}
			// 设置为:True,表示写入的时候追加数据
			fw = new FileWriter(F, false);
			// 回车并换行
			fw.write(content);
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (fw != null) {
				try {
					fw.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}

	public static String getTxtData(String loggerurl) throws IOException {
		//文件路径
		File fileTxt=new File(loggerurl);
		BufferedReader reader = null;//字符输入流进行读取操作读取
		String tempString = null;//每一行的内容
		//输入字节流，FileInputStream主要用来操作文件输入流
		FileInputStream intput = null;
		try {
			intput = new FileInputStream(fileTxt);
			reader = new BufferedReader(new InputStreamReader(intput));
			tempString = reader.readLine();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				reader.close();
				intput.close();
			} catch (IOException e) {
				e.printStackTrace();
			}

		}
		return tempString;
	}

}
