This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 15628

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.

Customer surveys are for companies who didn't pay proper attention to begin with.
Joel McNary

Joined: Aug 20, 2001
Posts: 1815
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
Similar Threads
ODBC connection to MS Access works standalone, but not as servlet
Access resources on mapped drives
connection to LDAP
ODBC connection to MS Access works standalone, but not as servlet
Can I use jdbc:odbc to access MS Access database remotely?