/**
* 生成数据下载结果文件至指定目录
* @param localDatePath 文件路径
* @param fileName 文件名
* @param downTaskPsgInfos 某趟航班下的旅客数据
*/
public void getDownTaskResultTxt(String localDatePath,String fileName,List<DownTaskPsgInfo> downTaskPsgInfos) {
// 判断文件路径是否存在,若不存在,先新建指定目录
File f=new File(localDatePath);
if(!f.exists())
f.mkdirs();
// 判断文件是否存在,若存在,先删除再写入一份最新的记录
File downTaskResultFile = new File(localDatePath+fileName);
if(downTaskResultFile.exists())
downTaskResultFile.delete();
BufferUtil fltFile = new BufferUtil();
BufferedWriter bufferW;
try {
bufferW = fltFile.getBw(localDatePath+fileName);
for(int i =0;i<downTaskPsgInfos.size();i++){
StringBuffer buffer = new StringBuffer("");
DownTaskPsgInfo downTaskPsgInfo = new DownTaskPsgInfo();
downTaskPsgInfo=downTaskPsgInfos.get(i) ;
// 将旅客订座记录中字段信息写入数据下载结果文件
buffer.append(downTaskPsgInfo.getDptAirptCd());
buffer.append(downTaskPsgInfo.getArrvAirptCd());
。。。。。。。
buffer.append(downTaskPsgInfo.getBkDay());
buffer.append(downTaskPsgInfo.getActionCd());
buffer.append("|");
buffer.append(downTaskPsgInfo.getPsgCnName());
buffer.append("|");
buffer.append(downTaskPsgInfo.getPnrInfo().replace("\r\n", "~"));
bufferW.write(buffer.toString());
bufferW.newLine();
}
bufferW.close();
} catch (IOException e) {
log.error("---> 生成数据文件失败 " + localDatePath+fileName);
e.printStackTrace();
}
log.info("---> 成功生成数据文件 " + localDatePath+fileName);
}
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
/**
* Time: 11:21:26
* Apply reader or writer buffer encodered in GBK.
*/
public class BufferUtil {
/**
* Create a BuffererdReader from the specified file.
*
* @param filename the file to be readed as GBK BufferedReader.
* @return <code>BufferedReader br</code>
*/
public BufferedReader getBr(String filename) throws IOException {
BufferedReader br = null;
br = new BufferedReader(new InputStreamReader(new FileInputStream(filename), "GBK"));
return br;
}
/**
* Create a BufferedWriter from the specified file.
*
* @param fileName the file to be added as GBK BufferedWriter
* which will be writed in.
* @return <code>BufferedWriter bw</code>
*/
public BufferedWriter getBw(String fileName) throws IOException {
BufferedWriter bw = null;
bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "GBK"));
return bw;
}
}