Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File System in java

 
Yogini Shirodkar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2545
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
refer to Java File System.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic