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.

Recommended Answers

All 2 Replies

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.

The problem had to do with seralization and is solve now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.