0

Whenever I load the object there are these random symbols around the data.

 public void Save()
   {

      try
      {

         System.out.println("Where would you like to Save?");

         File thefile = new File(Input.next());
         FileOutputStream fout = new FileOutputStream(thefile);
         ObjectOutputStream oos = new ObjectOutputStream(fout);
         oos.writeObject(list.getRoot());
         oos.flush();
         oos.close();
         fout.flush();
         fout.close();
      }
      catch (Exception e1)    
      {
         e1.printStackTrace();
      }
   }

   public void Load()
   {
      try
      {
         System.out.println("Where would you like to Load from?");

         BufferedReader reader = new BufferedReader(new FileReader(Input.next()));

         String line;    
         int count = 0;   
         list = new tree();

         while ((line = reader.readLine()) != null)
         {   
            System.out.println(line + "\n");
            list.Add(line);
            count++;
         }

         reader.close();        
      } catch (FileNotFoundException e1)
      {
         e1.printStackTrace();
      } catch (IOException x)
      {
         x.printStackTrace();
      }
   }

}

The object is a binary tree.

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by alemojarro
0

Can you post a complete program that compiles, executes and shows the problem?
It looks like you are writing the data in one format (in a binary format) and trying to read it as character data. The write and the read methods should match.
You should either:
Write an object and read an object.
or
Write text and read text.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.