炼虚期简介
炼虚期主要阐述的是文件的压缩与解压的IO操作
提供完整代码,代码在筑基期中
博主空间https://blog.csdn.net/JOElib?spm=1011.2266.3001.5343
https://blog.csdn.net/JOElib?spm=1011.2266.3001.5343化神期
https://blog.csdn.net/JOElib/article/details/123948498?spm=1001.2014.3001.5501元婴期
https://blog.csdn.net/JOElib/article/details/123913609?spm=1001.2014.3001.5501
public class HuffmanCode implements Serializable {
@Serial
private static final long serialVersionUID = 4420;
}
public static void fileZip(String srcPath,String desPath) {
try(var fis = new FileInputStream(srcPath);
var fos = new FileOutputStream(desPath);
var oos = new ObjectOutputStream(fos)
) {
var content = new byte[fis.available()];
fis.read(content);
byte[] huffmanBytes = huffmanCodeZip(content);
oos.writeObject(huffmanBytes);
oos.writeObject(HUFFMAN_CODES);
oos.writeObject(lastCount);
oos.flush();
fos.flush();
}catch (Exception e) {
e.printStackTrace();
}
}
public static void fileDeZip(String zipPath,String desPath) {
try(var fis = new FileInputStream(zipPath);
var ois = new ObjectInputStream(fis);
var fos = new FileOutputStream(desPath)
) {
var huffmanBytes = (byte[])ois.readObject();
var huffmanCodes = (Map)ois.readObject();
lastCount = (int)ois.readObject();
var content = decode(huffmanBytes,huffmanCodes);
fos.write(content);
fos.flush();
}catch (Exception e) {
e.printStackTrace();
}
}
解压后
大家伙学会了吗,本系列博客已经结束了喔,希望小伙伴们学有所成,如果有任何的不懂可以随时找我哦