This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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!!
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
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.
Joined: Jan 30, 2002
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.
Joined: Jan 30, 2002
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