• 大小: 13KB
    文件类型: .java
    金币: 1
    下载: 0 次
    发布日期: 2021-01-06
  • 语言: Java
  • 标签:

资源简介

哈夫曼树基本代码 将赫夫曼编码表存放在 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

评论

共有 条评论