fileprocess.java
来自「这是一个huffmanCode算法」· Java 代码 · 共 55 行
JAVA
55 行
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package lab6;import java.io.*;/** * * @author Administrator */public class FileProcess { /* Construct method */ int[] code = null; public FileProcess(){ /* add your code here */ code = new int[128]; for(int i = 0;i < code.length; i++) { code[i] = 0; } //构造一个int型数组,用来装载每个ASCII码出现的Freq。 } /* Process the file with given file name, and generate the frequency array */ public void processFile(String file){ /* add your code here */ File files = new File(file); if(!files.exists()){ System.out.println("cannot find the file!"); System.exit(0); } BufferedReader input = null; try{ input = new BufferedReader(new FileReader(file)); int read; while((read = input.read()) != -1){ code[read]++; } } catch(IOException e){ System.out.println("error!"); }//读取文件,建立Freq数组。 return; } /* Get the resulting frequency array of all the characters */ public int[] getFreq(){ /* add your code here */ return code; } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?