资源简介
哈夫曼树基本代码 将赫夫曼编码表存放在 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
评论
共有 条评论