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();
}
}

解决方案 »

  1.   

    补充:
    运行提示:
    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...
      

  2.   

    java.lang.ArrayIndexOutOfBoundsException: -1这的不是说越界么?
      

  3.   

    Haff_Node[] Haff_Tree = (Haff_Node[])in.readObject();Haff_Node[]的大小是多少呢?你把读到的值给这个赋值,Haff_Node没有指定大小,当然越界了
      

  4.   

    Haff_Node[] Haff_Tree = new Haff_Node[1000];
    然后再试试
      

  5.   

    我是搂住,经测试将Haff_Node[] Haff_Tree = (Haff_Node[])in.readObject();中Haff_Node[]去掉就可以