文件流,gzip解压,压缩
目录 文件画布 写入 (空文件
Fout=new File(Parent,entry.getName());)
FileOutputStream out=new FileOutputStream(Fout);
BufferedOutputStream Bout=new BufferedOutputStream(out);
其他流量基于基础包装文件--文件流---字节流 顺序
pbf一般是形成后再压缩
目录:
(new File(Fout.getParent())).mkdirs(); 建好目录
流:
File Fout=new File(Parent,entry.getName());) 建好空白画布--具体文件名
FileOutputStream fileOutputStream = new FileOutputStream("C:\\Desktop\\consiste.xlsx");
或
FileOutputStream out=new FileOutputStream(Fout);
BufferedOutputStream Bout=new BufferedOutputStream(out); 字符流
或ByteArrayOutputStream o = new ByteArrayOutputStream(1024) 字节流
Bout.toByteArray()
其他流量基于基础包装文件--文件流---字节流 顺序
需要读写的流经过 GZIPInputStream GZIPOutputStream 对应构造函数包装就有了对应加压解压功能
File file = new File("C:\\Users\\h.yu\\Downloads\\pbf\\pbf\\1669358890231_1669358895639.z.pbf");
File fileo = new File("C:\\Users\\h3.yu\\Downloads\\pbf\\pbf");
byte[] output = null;
FileInputStream fis = new FileInputStream(file);
File Fout =new File(fileo,"3313.pbf");
FileOutputStream out=new FileOutputStream(Fout);
GzipUtils.decompress(fis,out);
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
public class GzipUtils {
/**
* 数据解压缩
*
* @param is
* @param os
* @throws Exception
*/
public static void decompress(InputStream is, OutputStream os)
throws Exception {
GZIPInputStream gis = new GZIPInputStream(is);
int count;
byte data[] = new byte[1024];
while ((count = gis.read(data, 0, 1024)) != -1) {
os.write(data, 0, count);
}
gis.close();
}
/**
* 数据压缩
*
* @param is
* @param os
* @throws Exception
*/
public static void compress(InputStream is, OutputStream os)
throws Exception {
GZIPOutputStream gos = new GZIPOutputStream(os);
int count;
byte data[] = new byte[1024];
while ((count = is.read(data, 0, 1024)) != -1) {
gos.write(data, 0, count);
}
gos.finish();
gos.flush();
gos.close();
}
}