• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

saving JTree

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all.
Does anyone know how to code saving a JTree to a file. I want to be able to save a newly constructed Jtree to a file. Thanks.
 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Here is the code u can use to save a JTree. Remember that there is nothing special in a JTree. A JTree is an object too.
So let 'jtree' be the the JTREE object u want to save.
This code will help u save the JTREE in a file called 'MyObject'
try
{
FileOutputStream fos = new FileOutputStream("MyObject");
ObjectOutputStream oos= new ObjectOutputStream(fos);
oos.writeObject(jtree);
}
catch(Exception e)
{
}
Similarly u can read the fileobject using the follwing code
try
{
FileInputStream fis = new FileInputStream("MyObject");
ObjectInputStream oos= new ObjectInputStream(fis);
JTree jtree = (JTree)oos.readObject();
}
catch(Exception e)
{
}

 
m pap
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks.but one question
what if I want the file name to be an input from the user.
For instance the user was manapulating data, that by code is structured in a JTree, and wants to save their work. Therefore will save the changes to a file. I want to know how to save these changes to a jtree to a file. A file they will name. I hope I make sense.
All help is great.
thank you
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic