class Haff_Node implements Serializable
{
char ch;
String hcode;
int lchild;
int rchild;
int freq;
int flag;
int num;
}
我用这个方法存
//Haff_Tree是一个Haff_Node的数组
public void Save_Tree_to_Text()
{
try
{
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("Haff_tree.dat"));
out.writeObject(Haff_Tree);
out.close();
System.out.println("ok!save");
}
catch(Exception e)
{
e.printStackTrace();
}
}但是用这个方法读的时候,什么都读不出来
public void Load_Text_to_Tree()
{
try
{
ObjectInputStream in = new ObjectInputStream(new FileInputStream("Haff_tree.dat"));
Haff_Node[] Haff_Tree = (Haff_Node[])in.readObject();
in.close();
System.out.println("ok!load");
}
catch(Exception e)
{
e.printStackTrace();
}
}
{
char ch;
String hcode;
int lchild;
int rchild;
int freq;
int flag;
int num;
}
我用这个方法存
//Haff_Tree是一个Haff_Node的数组
public void Save_Tree_to_Text()
{
try
{
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("Haff_tree.dat"));
out.writeObject(Haff_Tree);
out.close();
System.out.println("ok!save");
}
catch(Exception e)
{
e.printStackTrace();
}
}但是用这个方法读的时候,什么都读不出来
public void Load_Text_to_Tree()
{
try
{
ObjectInputStream in = new ObjectInputStream(new FileInputStream("Haff_tree.dat"));
Haff_Node[] Haff_Tree = (Haff_Node[])in.readObject();
in.close();
System.out.println("ok!load");
}
catch(Exception e)
{
e.printStackTrace();
}
}
运行提示:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
at Haffman_Process.Haffman_Decompressor(haffman_finish.java:252)
at haffman_finish.main(haffman_finish.java:20)
Press any key to continue...
然后再试试