byte[] base64 = queryByte(“数据库取出的数据集合”, “存入txt文本的名称的地址” +".txt", “解压成zip文件存入的地址” + “.zip”);
// 如 C:TEST/test.txt
private byte[] queryByte(“数据集合”, String txtPath, String zipPath) throws IOException {
File file = new File(txtPath);
if (!file.isFile()) {
file.createNewFile();
}
BufferedWriter writer = new BufferedWriter(new FileWriter(txtPath));
for (XXXDTO obj : 数据集合) {
// 业务的逻辑
…
…
…
…
// 写入的数据信息
writer.write(obj.getSetlId)
}
writer.close();
TxtTotZipORBase64.txtTOzip(txtPath, zipPath);
return TxtTotZipORBase64.fileToByte(zipPath);
}
public static void txtTOzip(String txt, String zip) throws IOException {
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zip));
File file = new File(txt);
FileInputStream fis = new FileInputStream(file);
zos.putNextEntry(new ZipEntry(file.getName()));
zos.setComment("by zip test!");
byte[] buffer = new byte[1024];
int len = 0;
while ((len = fis.read(buffer)) > 0) {
zos.write(buffer, 0, len);
}
fis.close();
//外置
zos.closeEntry();
zos.close();
}