从文件读取对象
/**
* get file path from object file
* @return
*/
private Object getPath() {
FileInputStream fin=null;
ObjectInputStream ios=null;
StringBuffer exportdir = new StringBuffer().append(Glob.tempdir());
if(exportdir.charAt(exportdir.length()-1) != File.separatorChar)
exportdir.append(File.separator);
exportdir.append("saveExportAuditLogsExcelPath.bin");
Object path = "";
try {
fin = new FileInputStream(exportdir.toString());
ios = new ObjectInputStream(fin);
path = ios.readObject();
ios.close();
fin.close();
} catch (FileNotFoundException e) {
logger.error(e);
e.printStackTrace();
} catch (IOException e) {
logger.error(e);
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return path;
}
将对象存入到文件
/**
* save file path to object file
* @param path
*/
private void savePath(Object path) {
FileOutputStream fos;
StringBuffer exportdir = new StringBuffer().append(Glob.tempdir());
if(exportdir.charAt(exportdir.length()-1) != File.separatorChar)
exportdir.append(File.separator);
exportdir.append("saveExportAuditLogsExcelPath.bin");
try {
fos = new FileOutputStream(exportdir.toString());
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(path);
oos.close();
fos.close();
} catch (FileNotFoundException e) {
logger.error(e);
e.printStackTrace();
} catch (IOException e) {
logger.error(e);
e.printStackTrace();
}
}