Posted By:
Shriram_Ethirajan
Posted On:
Tuesday, March 26, 2002 12:06 AM
hi,
use the fileoutputstream to save the tree back to file.i will give u a sample code and try it.
.
..
....
else if(e.getActionCommand().equals("Save"))
{try {
fs = new FileOutputStream(fname,false);
callrec();
fs.close();
refreshUI(fname); // build the tree
...
..
.
declare the fileo/pstream in the class
where u make declarations.
callrec() is a method which contains code as ..
public void callrec() {
Object st = m_tree.getModel().getRoot();
System.out.println("
");
System.out.println("Root is ::"+st);
DefaultMutableTreeNode mtn = (DefaultMutableTreeNode)st;
TreeNode tn = mtn.getFirstChild();
System.out.println("first child::"+tn);
try
{
String s = tn.toString()+"
";
byte b[];
b=s.getBytes();
fs.write(b);
}
catch(Exception eq)
{
System.out.println(eq);
}
MutableTreeNode mt = (MutableTreeNode)tn;
recursive(mt); // another method
if (mt.getChildCount() > 0)
{
byte bb[];
String s = mt.toString();
s = ""+ s.substring(1,s.length())+"
";
bb = s.getBytes();
try {
fs.write(bb);
}
catch(Exception e){}
System.out.println(s);
}
.
..
...
public void recursive(MutableTreeNode tm)
{ try
{
for(int i=0;i {
MutableTreeNode dts = (MutableTreeNode)tm.getChildAt(i);
String s = dts.toString();
System.out.println(s);
byte b[];
b = s.getBytes();
fs.write(b);
if (dts.getChildCount() > 0 )
{
recursive(dts);
}
if (dts.getChildCount() > 0)
{
byte bb[];
s = ""+ s.substring(1,s.length())+"
";
bb = s.getBytes();
fs.write(bb);
System.out.println(s);
}
}
}//try
catch(Exception ew)
{
ew.printStackTrace();
}
}
if u r not clear mail me.