資源簡介
哈夫曼樹基本代碼 將赫夫曼編碼表存放在 Map<Byte,String> 形式在生成赫夫曼編碼表示,需要去拼接路徑, 定義一個StringBuilder 存儲某個葉子結點的路徑
代碼片段和文件信息
package?com.aaa.huffmancode;
import?java.io.*;
import?java.util.*;
/**
?*?@date?2020/4/22
?*/
public?class?HuffmanCode?{
????public?static?void?main(String[]?args)?{
???????/*
????????String?content?=?“I?love?China?I?like?Java??f“;
????????//獲取字符串的字節數組
????????byte[]?contentBytes?=?content.getBytes();
????????//交由赫夫曼編碼處理
????????byte[]?huffmanCodeBytes?=?huffmanZip(contentBytes);
????????//進行打印
????????System.out.println(“壓縮后=“+Arrays.toString(huffmanCodeBytes));
????????//解碼
????????byte[]?sourceBytes?=?decode(huffmanCodeshuffmanCodeBytes);
????????System.out.println(“解碼后=“+new?String(sourceBytes));
????????*/
????????//壓縮文件
????????String?srcFile?=?“D:\\Downloads\\1.jpg“;
????????String?dstFile?=?“D:\\Downloads\\1jpg.zip“;
????????zipFile(srcFile?dstFile
- 上一篇:利用javaFX寫萬年歷
- 下一篇:手機RFID開發SDK
評論
共有 條評論