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.
Sajee Joseph
Ranch Hand
Joined: Jan 17, 2001
Posts: 200
posted
0
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
Joined: Jun 13, 2001
Posts: 13
posted
0
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
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.