File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Java trees Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java trees" Watch "Java trees" New topic

Java trees

Maha Hassan
Ranch Hand

Joined: Aug 02, 2005
Posts: 133

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??


Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15041

Class represents a path to a file or directory. It contains methods to list the subdirectories and files in a directory.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Maha Hassan
Ranch Hand

Joined: Aug 02, 2005
Posts: 133
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?

Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Maha Hassan
Ranch Hand

Joined: Aug 02, 2005
Posts: 133
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.

I agree. Here's the link:
subject: Java trees
It's not a secret anymore!