File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes File System in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "File System in java" Watch "File System in java" New topic
Author

File System in java

Yogini Shirodkar
Greenhorn

Joined: May 22, 2003
Posts: 3
Hi All,
From java is it possible to locate the root directories and files residing them, from the machines in the local network ?
I want something like network neighbourhood type application , so that i can view and select file from network machine
Thanks in advance!!
John Lee
Ranch Hand

Joined: Aug 05, 2001
Posts: 2545
refer to Java File System.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
From java is it possible to locate the root directories and files residing them, from the machines in the local network ?
The static method File.listRoots() returns a File[] array listing all the system root directories. On Unix OSs, including Linux, that will return the single root directory ("/"); on Windows platforms it will return the roots of all mounted drives on the system. You can then recursively create a tree structure of the file systems by testing whether or not each file is a directory with File.isDirectory() and if it is you can call File.listFiles() which also returns a File[] array.
[ May 28, 2003: Message edited by: Michael Morris ]

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

Note that, on Windows, this just lists the roots of those directories that have lettered drives (have been mounted). This does not return machine names on the network neighborhood (or from the Chooser if you're on a Mac ). I'm not sure how one would go about getting that information....


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
I'm not sure how one would go about getting that information....
When Sun gets off their ass and gives us raw sockets so we can query the network.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Here's some code I wrote a while back showing how to create a JTree of the local file system. This code is very inefficient, it takes over two minutes on my machine to create the top level node in the tree. So be patient and be warned.
ExplorerTree.java

TreeExplorer.java
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File System in java