File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes General Computing and the fly likes How do i get the drive names Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » General Computing
Bookmark "How do i get the drive names" Watch "How do i get the drive names" New topic

How do i get the drive names

Uma Lade

Joined: Jun 27, 2003
Posts: 5
whenever i log into some novell server, some folders of the novell server will be mapped to some of my drives. For example I: is mapped \\MRS01\Data. Through java, how do get the drive name? I want retrieve the name of I: as \\MRS01\Data.
I would be very much grateful if somebody can help me out.

Thanks & Regards<br />Uma
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

You can get the basic information about the filesystem by using the class to read in the directory you get back from a "new"/")" call.
I haven't checked to see how multiheaded filesystems like Windows handles that, but there are ways, and, as far as I'm aware, Sun has allowed for them.
Note, however, that OS-specific file and filesystem information retrieval is not supported by Java, since that would violate the "write once run anywhere" mandate. So in order to find out, for example, how much free space was on a WIndows disk drive, you'd have to use a JNI class.

An IDE is no substitute for an Intelligent Developer.
Joel McNary

Joined: Aug 20, 2001
Posts: 1824

There's the static method (I think that's what it's called...) that will return all the root directories of the system. For UNIX, that's just "/", but on Windows it's {C:\, D:\, I:\, etc.}
However, that does not support either obtaining network drives or obtaining the network name of the mapped drive. AFAIK, Java does not support this type of file naming (\\SomeMachine\directory\)

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
george pii

Joined: May 14, 2004
Posts: 1
Here is a script/class that gets the mapped address on a Wintel machine. It gets the network address that is mapped to drive letter "P:". The loop can be changed to print all maps and lots of other things.

// ============================================================
import* ;

* <P>
* <BR>Created May 14, 2004
* @author George Pii
public class MappedDriveAddresses
public static void main(String[] args) throws Exception
Runtime runTime = Runtime.getRuntime() ;
Process process = runTime.exec( "net use" ) ;

InputStream inStream = process.getInputStream() ;
InputStreamReader inputStreamReader = new InputStreamReader( inStream ) ;
BufferedReader bufferedReader = new BufferedReader( inputStreamReader ) ;

String line = null ;
String [] components = null ;
while( null != (line = bufferedReader.readLine() ) )
{ //System.out.println( line ) ;
components = line.split( "\\s+" ) ;

if ( (2 < components.length) && (components[1].equals("P:")) )
{ System.out.println( components[2] ) ; }

// ====================================================================
I agree. Here's the link:
subject: How do i get the drive names
It's not a secret anymore!