csv 日志的写入与读取
来源:互联网 发布:excel表格数据统计分类 编辑:程序博客网 时间:2024/05/16 00:40
/**
*
* @author weij
*
*/
public class LogDto {
int idx;
String logType;
String logName;
String dataTime;
String owner;
public String getLogType() {
return logType;
}
public void setLogType(String logType) {
this.logType = logType;
}
public String getLogName() {
return logName;
}
public void setLogName(String logName) {
this.logName = logName;
}
public String getDataTime() {
return dataTime;
}
public void setDataTime(String dataTime) {
this.dataTime = dataTime;
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
public int getIdx() {
return idx;
}
public void setIdx(int idx) {
this.idx = idx;
}
}
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
public class WriteLog {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
private void writeLog(String fileName, LogDto dto)
{
// 指定的目录下创建备份Log文件
FileWriter fileWriter = null;
try {
fileWriter = new FileWriter("d:/backup/Log_Detail.csv", true);
BufferedWriter write = new BufferedWriter(fileWriter);
StringBuffer msg = new StringBuffer();
msg.append(dto.getLogType()+ ",");
msg.append(dto.getLogName() + ",");
msg.append(dto.getDataTime() + ",");
msg.append(dto.getOwner());
write.write(msg.toString()); //写入日志内容
write.newLine();
write.flush();
write.close();
} catch (IOException e) {
}finally{
try {
if(fileWriter != null){
fileWriter.close();
}
} catch (IOException e) {
}
}
}
}
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class GetLogDtoList {
/**
* 取得所有备份Oracle的日志信息
* @return
* @throws ServiceException
*/
public List<LogDto> getDbBackupDtoList(){
// TODO Auto-generated method stub
List<LogDto> dtoList = new ArrayList<LogDto>();
// 读取备份日志文件
String sFileName = "d:/backup/DB_Backup_Detail.csv";
FileReader fr = null;
BufferedReader br = null;
try {
fr = new FileReader(sFileName);
br = new BufferedReader(fr);
String sRecord = null;
int idx = 0;
while ((sRecord = br.readLine()) != null) {
String[] strArray = sRecord.split(",");
if(strArray.length != 4){
continue;
}
LogDto dto = new LogDto();
dto.setIdx(++idx);
dto.setLogType(strArray[0]);
dto.setLogName(strArray[1]);
dto.setDataTime(strArray[2]);
dto.setOwner(strArray[3]);
dtoList.add(dto);
}
} catch (FileNotFoundException e) {
} catch (IOException e) {
}finally{
try {
if(br != null) br.close();
if(fr != null) fr.close();
} catch (IOException e) {
}
}
return dtoList;
}
}
- csv 日志的写入与读取
- .csv文件的读取与写入
- Python对于CSV文件的读取与写入
- python实现txt/csv的读取和写入txt/csv!
- CSV读取和写入
- python读取与写入csv EXCEK HDF 文件
- 写入文件 csv 与 xls的区别
- python读取、写入csv数据:csv模块
- python 读取csv和写入csv
- java 读取 写入 csv 文件
- php对csv文件的读取,写入,输出下载操作
- php对csv文件的读取,写入,输出下载操作
- php对csv文件的读取,写入,输出下载操作
- PHP读取、写入、删除CSV文件的操作
- php对csv文件的读取,写入,输出下载操作
- php对csv文件的读取,写入,输出下载操作
- 用python 读取和写入CSV格式的文件
- CsvHelper, 帮助读取和写入CSV文件的库
- 别追女人太紧
- 摩托罗拉Android新机Opus One参数曝光
- as3操作xml之二
- 取得文件夹下的所有文件的文件名和文件大小
- Android building system
- csv 日志的写入与读取
- 配置vlan与chunk
- as3访问父级和子级变量
- CNNIC开通举报不良域名通道 举报者可获200元礼品
- 给美国做的感应触摸键控制器发货了!
- pb10连接到sql server
- 数据库设计三大范式应用实例剖析
- 低通滤波在多节点非对称负载调度中的一个应用
- 一个分隔函数