Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java trees

 
Maha Hassan
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to represent the hierarchy of folder using java (not GUI) so that I can print the top level in it and all the details.

Is there a way to do that in Java, or do I have to impalement my own tree??

Thanks,

Maha
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15448
42
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class java.io.File represents a path to a file or directory. It contains methods to list the subdirectories and files in a directory.
 
Maha Hassan
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mean, I am reading a certain hierarchy(not form a directory) and I want to represent it in a tree form.

Is there a thing like that?

Thanks.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the Tree classes from Swing even if you don't have a GUI. See if any implementation of TreeNode works for you, or make your own. If you get stuck, post some code and we'll try to bump you along.
 
Maha Hassan
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all for reply,

I used the implementations of binary tree to create my tree (not binary). I just removed the normal left and right children with array list to have more than one child

Thanks all.

Maha
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic