Chinaunix首页 | 论坛 | 博客
  • 博客访问: 154409
  • 博文数量: 43
  • 博客积分: 1470
  • 博客等级: 上尉
  • 技术积分: 354
  • 用 户 组: 普通用户
  • 注册时间: 2009-09-16 14:58
个人简介

这真是个好网站我要努力工作

文章分类

全部博文(43)

文章存档

2015年(2)

2014年(17)

2011年(1)

2010年(2)

2009年(21)

我的朋友

分类: Java

2009-10-27 09:34:19

package cn.yicha.ask.AskBaidu;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.HashMap;
import java.util.concurrent.ConcurrentLinkedQueue;

import org.apache.log4j.Logger;

public class AskBaidu_Inti {
private static final Logger log = Logger.getLogger(AskBaidu_Inti.class.getName());
public static HashMap askmap = new HashMap();
public static File cachefile =null;
public static void askinit( )
{
cachefile = getCacheFile();
log.info(cachefile.getAbsoluteFile()+"存放序列化文件的路径");
if(!initQueue()){
askmap = new HashMap();
log.info("Build mobileBindCheckCodesQueue");
}
}
//构建存放文件的路径
private static File getCacheFile() {
String classpath = System.getProperty("java.io.tmpdir");
String separator = System.getProperty("file.separator");
return new File(classpath+separator+"QueueFile.dat");
}
//反序列化方法
public static boolean initQueue(){
ObjectInputStream in;
try {
in = new ObjectInputStream(new FileInputStream(cachefile));
askmap = (HashMap) in.readObject();
if(askmap != null){
log.info("Init mobileBindCheckCodesQueue from cache File :"+cachefile);
return true;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return false;
}
//序列化方法
public static void saveQueue(){
ObjectOutputStream out;
try {
out = new ObjectOutputStream(new FileOutputStream(cachefile));
out.writeObject(askmap);
out.flush();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
log.info("Save mobileBindCheckCodesQueue to cachefile:"+cachefile);
}
    public static void main(String[] args)
    {
     AskBaidu_Inti ai = new AskBaidu_Inti();
     ai.askinit();
    }
}

阅读(748) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~