`
itwangxinli
  • 浏览: 143710 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论
阅读更多
package com.seahigh.tyt.acs.util;

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
/**
 * 
 * @author 汪心利
 * @Create Time 2009-2-5下午05:05:16
 * @CopyRight (C) seahigh 2009
 */
public class FileUtil {
	private String csvFilePath;

	/**
	 * CSV file name(文件名only)
	 * 
	 * @param yyyyMMddHH
	 * @throws IOException
	 */
	public FileUtil(String logDir, String yyyyMMddHH) throws IOException {
		csvFilePath = logDir + yyyyMMddHH + ".csv";
	}

	/**
	 * 将data数据写入CSV
	 * 
	 * @param data
	 * @param fileName
	 * @throws IOException
	 * @throws IOException
	 */
	public synchronized void wirteDataAsCsvFile(String data) throws IOException {
		FileWriter writer = null;
		try {
			writer = new FileWriter(csvFilePath, true);
			writer.write(data + ";");
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (writer != null)
				writer.close();
		}

	}
//主要是这个方法了
	public synchronized void writePrefermanceData(HashMap perfermance)
			throws IOException {
		// FileWriter writer = null;
		BufferedOutputStream outputStream = null;
		try {
			// writer = new FileWriter(csvFilePath, true);
			outputStream = new BufferedOutputStream(new FileOutputStream(
					csvFilePath, true));
			StringBuffer str = new StringBuffer();
			str.append(Util.getDateTime(null)).append(",");
			List list = PrefermanceOrder.getInstance().getOrder();
			for (int i = 0; i < list.size(); i++) {
				// System.out.println(list.get(i)+"="+perfermance.get(list.get(i)));
				str.append(perfermance.get(list.get(i))).append(",");
			}
			// writer.write(str.substring(0, str.length() - 1) + ";");
			outputStream.write((str.substring(0, str.length() - 1) + ";")
					.getBytes());
			outputStream.flush();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			// if (writer != null)
			if (outputStream != null) {

				outputStream.close();
			}
			// writer.close();
		}
	}
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics