This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Java in General and the fly likes Writing / reading JTree to/from xml / html file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Writing / reading JTree to/from xml / html file" Watch "Writing / reading JTree to/from xml / html file" New topic

Writing / reading JTree to/from xml / html file

John Vorwald
Ranch Hand

Joined: Sep 26, 2010
Posts: 139

I need some help in writing / reading a jtree to a binary file and also to an html file.

A program uses a jtree to create / investigate structural modifications to an analytical model. As the program runs, the various perturbations of the analytical model are added to the tree, and the perturbations evaluated with summary performance results stored in the tree, and the more successful performing leafs are explored / expanded further. I need to write the jtree data to a file as additional leafs are added to the tree, and then read in a previously written tree when the program restarts.

I can probably implement a tree traversal and write out either a binary or text representation of the tree, but haven't done this before, so any suggestions on writing / reading a jtree to a file would be appreciated.

Also, it would be advantageous to write out an html file of the tree structure that could be viewed using a browser so the progress / solution could be investigated while the program continues to run.

Each leaf of the tree holds quite a bit of data that defines a model topology (inputs, outputs, model structure, number of submodels, etc) and also contains summary performance data of the submodels. The submodels of a leaf are essentially trivial variations of the leaf's model.

This program will run for a long time, think years, and essentially continuously evaluate / optimize the model structures as new data becomes available. There will probably be times when the evolution of the performance of optimal model structures is reviewed, so a "archival" copy of the current tree should be written out at some interval, like every two weeks, and also whenever model results are utilized (random intervals).
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
According to the javax.swing.JTree JavaDocs, serializing a JTree is only recommended for short term use and points to java.beans.XMLEncoder for the preferred way of storage.

I would certainly look into XMLEncoder.

I agree. Here's the link:
subject: Writing / reading JTree to/from xml / html file
It's not a secret anymore!