BufferedOutputStream outputStream=null;
try {
//创建读取文件流的目录
outputStream = new BufferedOutputStream(new FileOutputStream(outputFile,true));
String count ="4";
String head ="zzp";
String state ="sydw=001|pjbm=002003|date=20130101-20131231xxx|";
String symbol="#";
byte[] b = null;
//写总的结构数据
b =count.getBytes("gb2312");
outputStream.write(b);
b =symbol.getBytes("gb2312");
outputStream.write(b);
//写头信息
b =head.getBytes("gb2312");
outputStream.write(b);
b =symbol.getBytes("gb2312");
outputStream.write(b);
//写状态信息
b =state.getBytes("gb2312");
outputStream.write(b);
b =symbol.getBytes("gb2312");
outputStream.write(b);
outputStream.flush();
File directory = new File(inputfile);
File[] fileList = directory.listFiles();
String fileInfo ;
//写每个文件的文件名和长度
for(int i=0;i<=fileList.length-1;i++)
{
String fileName = fileList[i].getName();
Long filelen = fileList[i].length();
fileInfo = fileName+"-"+filelen.toString();
b =fileInfo.getBytes("gb2312");
outputStream.write(b);
outputStream.flush();
b =symbol.getBytes("gb2312");
outputStream.write(b);
}
for(int i=0;i<=fileList.length-1;i++)
{
byte[] bytes=FileUtils.readFileToByteArray(fileList[i]);
outputStream.write(bytes);
outputStream.flush();
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
//创建读取文件流的目录
outputStream = new BufferedOutputStream(new FileOutputStream(outputFile,true));
String count ="4";
String head ="zzp";
String state ="sydw=001|pjbm=002003|date=20130101-20131231xxx|";
String symbol="#";
byte[] b = null;
//写总的结构数据
b =count.getBytes("gb2312");
outputStream.write(b);
b =symbol.getBytes("gb2312");
outputStream.write(b);
//写头信息
b =head.getBytes("gb2312");
outputStream.write(b);
b =symbol.getBytes("gb2312");
outputStream.write(b);
//写状态信息
b =state.getBytes("gb2312");
outputStream.write(b);
b =symbol.getBytes("gb2312");
outputStream.write(b);
outputStream.flush();
File directory = new File(inputfile);
File[] fileList = directory.listFiles();
String fileInfo ;
//写每个文件的文件名和长度
for(int i=0;i<=fileList.length-1;i++)
{
String fileName = fileList[i].getName();
Long filelen = fileList[i].length();
fileInfo = fileName+"-"+filelen.toString();
b =fileInfo.getBytes("gb2312");
outputStream.write(b);
outputStream.flush();
b =symbol.getBytes("gb2312");
outputStream.write(b);
}
for(int i=0;i<=fileList.length-1;i++)
{
byte[] bytes=FileUtils.readFileToByteArray(fileList[i]);
outputStream.write(bytes);
outputStream.flush();
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}