Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Data Structures Exploring the Java Collection Framework Using ArrayLists

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

load() method

Hey folks,

I can´t see where treets from

 Treet[] treets = Treets.load();

take the Treets from. The next line gives us an integer with the number of treets, but inside the load() method there is no reference to our Treets.

How does the load() method get the Treets???

Thanks a lot


1 Answer

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

In the file Treets.java, the load() method reads the "treets.ser" file that contains the serialized treet information:

  public static Treet[] load() {
    Treet[] treets = new Treet[0]
    try (
      FileInputStream fis = new FileInputStream("treets.ser");  //<-- Load treets from serialized data
      ObjectInputStream ois = new ObjectInputStream(fis);
    ) {
      treets = Treet[] ois.readObject();  //<-- Convert to our 'treets' object
    } catch(IOException ioe) {
      System.out.println("Error reading file");
    } catch(ClassNotFoundException cnfe) {
      System.out.println("Error loading treets");
    return treets;