package com.helper.doAction;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Map.Entry;

import com.helper.Swap.Swap;

/**
 * 小说窗口关闭的时候更新记录文件
 * @author Administrator
 *
 */
public class NovelWindowClose {
	public NovelWindowClose() {
		Swap.historyNovel.put(Swap.novelName, Swap.novelParagraphTemp);//把新的段落记录更新进去
		File novelHistoryFile = new File("novel.his");
		// 存在历史文件
		if (novelHistoryFile.exists()) {
			try {
				WriteConfigFile(novelHistoryFile);
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		} else {
			// 不存在则创建
			try {
				novelHistoryFile.createNewFile();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
			try {
				WriteConfigFile(novelHistoryFile);
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		}
	}

	/**
	 * 写记录文件
	 * 
	 * @throws IOException
	 */
	public void WriteConfigFile(File file) throws IOException {
		StringBuilder builder = new StringBuilder("");
		for (Entry<String, Integer> entry : Swap.historyNovel.entrySet()) {
			System.out.println(entry.getKey() + "--->" + entry.getValue());
			builder.append(entry.getKey() + "――" + entry.getValue() + "\n");
		}
		BufferedWriter output = new BufferedWriter(new FileWriter(file));
		output.write(builder.toString());
		output.close();
	}
}
最近下载更多
xp95323  LV14 2023年11月27日
微信网友_5852742079762432  LV6 2022年3月2日
wanglinddad  LV54 2022年2月11日
baoxing567  LV9 2021年3月30日
dengdai2018  LV6 2021年2月28日
675104182  LV14 2020年9月22日
yuqm  LV17 2020年8月3日
tinbe  LV11 2018年12月19日
jasyr1314  LV11 2018年10月20日
Weipeng_  LV14 2018年6月22日
最近浏览更多
Dominick  LV14 3月5日
xp95323  LV14 2023年11月27日
xingxing1234  LV10 2023年3月22日
Hsy605  LV9 2022年6月20日
1265260263  LV4 2022年4月8日
微信网友_5852742079762432  LV6 2022年2月28日
wanglinddad  LV54 2022年2月9日
敲代码真难 2021年12月13日
暂无贡献等级
15116483404  LV2 2021年12月3日
506667372  LV3 2021年10月18日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友