File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Spring in Action this week in the Spring 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
Author

How do i get the drive names

Uma Lade
Greenhorn

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: 16137
    
  21

You can get the basic information about the filesystem by using the java.io.File class to read in the directory you get back from a "new java.io.File("/")" 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
Bartender

Joined: Aug 20, 2001
Posts: 1821

There's the static java.io.File.getFileRoots() 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
Greenhorn

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 java.io.* ;

/**
*
* <P>MappedDriveAddresses.java
* <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: http://aspose.com/file-tools
 
subject: How do i get the drive names